2012-12-28 33 views
1

我在Access 2010中的VBA代碼有問題。我聲明一個類型,但是當我嘗試獲取此類型的變量的指針(與函數VarPtr)時,我得到一個compilation error: incompatible type訪問2010 VBA ptrVar不工作

Dim dm As DEVMODE 
Dim pd As PRINTER_DEFAULTS 

pd.pDevMode = VarPtr(dm) ' the line that throws the error 

' pDevMOde is a Long that is supose to contain the adress of the dm variable 

Private Type DEVMODE 
    dmDeviceName As String * CCHDEVICENAME ' (1 To CCHDEVICENAME) As Byte 
    dmSpecVersion As Integer 
    dmDriverVersion As Integer 
    dmSize As Integer 
    dmDriverExtra As Integer 
    dmFields As Long 
    dmOrientation As Integer 
    dmPaperSize As Integer 
    dmPaperLength As Integer 
    dmPaperWidth As Integer 
    dmScale As Integer 
    dmCopies As Integer 
    dmDefaultSource As Integer 
    dmPrintQuality As Integer 
    dmColor As Integer 
    dmDuplex As Integer 
    dmYResolution As Integer 
    dmTTOption As Integer 
    dmCollate As Integer 
    dmFormName As String * CCHFORMNAME '(1 To CCHFORMNAME) As Byte 
    dmUnusedPadding As Integer 
    dmBitsPerPel As Integer 
    dmPelsWidth As Long 
    dmPelsHeight As Long 
    dmDisplayFlags As Long 
    dmDisplayFrequency As Long 
End Type 

問題是,此代碼是在早期版本的Access中創建的,並且在版本2003和更高版本中完美工作。我不知道爲什麼它在Access 2010中不起作用。我研究了2010和2003版本之間的差異,但我沒有發現任何與此相關的內容。

有沒有人有線索?

謝謝!

+0

我希望你能找到我的評論:)我正在嘗試一些類似的代碼......「PRINTER_DEFAULTS」這個類型在哪裏定義,我需要添加哪些引用來獲取它 –

回答

3

我終於找到了問題。 實際上在64位版本中有所不同。該VarPtr不再返回 一個長型,它返回一個LongPtr類型變量和我的代碼是不是能夠把LongPtr到龍

參考這裏:http://msdn.microsoft.com/en-us/library/ee691831.aspx

VarPtr | 變體轉換器。 |在64位版本上返回LongPtr,在32位版本上返回Long(4字節)。

希望它可以幫助別人!