初學者可以新建一個空白數據庫進行測試,在空白數據庫裡面任意新建一個窗體,進入該窗體代碼區(alt+f11),將如下代碼復制進去保存,再運行關閉新建的窗體,就可以看到主窗體右上角關閉按鈕失效了.
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Sub Form_Open(Cancel As Integer)
'取消Access主窗體中的“關閉”按鈕
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060
Dim hMenu As Long
hMenu = GetSystemMenu(Application.hWndAccessApp, 0)
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
End Sub