2016-01-06 157 views
0

我已經寫在表格點擊按鈕下面的代碼,它應該在MS-訪問返回當前屏幕尺寸MS-Access中,VBA錯誤

Option Compare Database 

Declare Function GetSystemMetrics32 Lib "User32" _ 
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long 


Private Sub Command0_Enter() 


Dim w As Long, h As Long 
    w = GetSystemMetrics32(0) ' width in points 
    h = GetSystemMetrics32(1) ' height in points 

End Sub 

我收到以下錯誤:

The expression On Open you entered as the event property setting produced the following error: Only comments may appear after End Sub, End Function or end property

enter image description here

回答

0

Declare Function語句需要到外面(上面)Private Sub Command0_Enter()

+0

除此之外,您必須在表單模塊中使用'Private Declare',或將其放入公共模塊中。 – Andre

+0

我做了更改,仍然是相同的問題 – user580950

+0

我建議你再檢查一次,因爲上面的例子對我來說工作正常,一旦我把'Private Declare'而不是'Declare'作爲函數 – GavinP