troubleshooting Question

Stuck again on Ms Access API declaration

Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia asked on
Microsoft Access
2 Comments1 Solution10 ViewsLast Modified:
Dear All;
I’m trying to make the code below work in Office 2010,2016 & 2019 in both 32 & 64 BIT I’m not familiar with the declaration of APIs but unfortunately, I cannot runaway from them. Kindly see how best the declaration can be done safely and correctly.  

Option Compare Database


Option Explicit
#If Win64 Then
Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal wRevert As Long) As Long
#Else
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal wRevert As Long) As Long
#End If
#If Win64 Then
Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long


#Else
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
#End If


Public Sub AccessCloseButtonEnabled(pfEnabled As Boolean)
  ' Comments: Control the Access close button.
  '           Disabling it forces the user to exit within the application
  ' Params  : pfEnabled       TRUE enables the close button, FALSE disabled it
  ' Owner   : Copyright (c) FMS, Inc.
  ' Source  : Total Visual SourceBook
  ' Usage   : Permission granted to subscribers of the FMS Newsletter


  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

Very much appreciated from Jimm (VIP) he tried to help but I missed him somewhere. See below the picture that I'm getting:




Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros