MS Access 2003: Hide Close button on Access program
This MSAccess tutorial explains how to hide the close button on the Access program in Access 2003 (with screenshots and step-by-step instructions).
Question: In Microsoft Access 2003/XP/2000/97, I have provided a command button to close the database. I was trying to figure out how to disable the (x) close button on top right so the user would have to use the command button.
Answer: You can disable the Close button on the Access program using VBA code.
Open your Access database, click on the Modules tab and create a new Module. Paste in the following code:
Private Const GWL_EXSTYLE = (-20) Private Const GWL_STYLE = (-16) Private Const WS_MAXIMIZEBOX = &H10000 Private Const WS_MINIMIZEBOX = &H20000 Private Const WS_SYSMENU = &H80000 Private Const HWND_TOP = 0 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const SWP_FRAMECHANGED = &H20 Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED Private Declare Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" (ByVal hwnd As Long, _ ByVal nIndex As Long, ByVal dwNewLong As Long) _ As Long Private Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hwnd As Long, _ ByVal nIndex As Long) As Long Private Declare Function SetWindowPos Lib "user32" _ (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _ ByVal x As Long, ByVal y As Long, ByVal cx As Long, _ ByVal cy As Long, ByVal wFlags As Long) As Long Sub HideAccessCloseButton() Dim lngStyle As Long lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE) lngStyle = lngStyle And Not WS_SYSMENU Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle) Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME) End Sub
Now when you view your Access program, you can see that the close button in the top right corner is visible.
Now, execute the following VBA code:
Private Sub Command0_Click() HideAccessCloseButton End Sub
Now, when you view your Access program, the Close button in the top right corner will no longer be visible.
This MSAccess tutorial explains how to Unhide the Close button on an Access program.
Advertisements