Hi. I have a bit of code that is designed to disable an user from closing the database via the top-right corner "X". Instead they follow the method setup in my own database to Close the Database. I've done this as there are some data that may be left in limbo if the database isn't saved correctly.
Anyway, I found some code that was viable for 32-bit systems but wanted to fix it up so that it can work on 64-bit systems too. I've added the PtrSafe and LongPtr keywords to the code. So the Declare Functions work. But the actual code for disabling the close database is giving a compile error.
I'm receiving a compile error type mismatch on lngMenu = GetSystemMenu(lngWindow, 0) .. how do I fix this?
Anyway, I found some code that was viable for 32-bit systems but wanted to fix it up so that it can work on 64-bit systems too. I've added the PtrSafe and LongPtr keywords to the code. So the Declare Functions work. But the actual code for disabling the close database is giving a compile error.
Code:
Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As LongPtr, ByVal wRevert As Boolean) As LongPtr
Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Boolean
Public Sub AccessCloseButtonEnabled(pfEnabled As Boolean)
On Error Resume Next
Const clngMF_ByCommand As Long = &H0&
Const clngMF_Grayed As Long = &H1&
Const clngSC_Close As Long = &HF060&
Dim lngWindow As Long
Dim lngMenu As Long
Dim lngFlags As Long
lngWindow = Application.hWndAccessApp
lngMenu = GetSystemMenu(lngWindow, 0)
If pfEnabled Then
lngFlags = clngMF_ByCommand And Not clngMF_Grayed
Else
lngFlags = clngMF_ByCommand Or clngMF_Grayed
End If
Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
End Sub
I'm receiving a compile error type mismatch on lngMenu = GetSystemMenu(lngWindow, 0) .. how do I fix this?