By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

64-bit Issue when Compiling

100+
P: 144
Found this code off a google search to remove the close "X" from the title bar. But when I go to compile it throws an error.

Compile error: The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them PtrSafe attribute.

Expand|Select|Wrap|Line Numbers
  1. Private Const GWL_EXSTYLE = (-20)
  2. Private Const GWL_STYLE = (-16)
  3.  
  4. Private Const WS_MAXIMIZEBOX = &H10000
  5. Private Const WS_MINIMIZEBOX = &H20000
  6. Private Const WS_SYSMENU = &H80000
  7.  
  8. Private Const HWND_TOP = 0
  9. Private Const SWP_NOMOVE = &H2
  10. Private Const SWP_NOSIZE = &H1
  11. Private Const SWP_FRAMECHANGED = &H20
  12. Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
  13.  
  14. Private Declare Function SetWindowLong Lib "user32" _
  15. Alias "SetWindowLongA" (ByVal hwnd As Long, _
  16. ByVal nIndex As Long, ByVal dwNewLong As Long) _
  17. As Long
  18. Private Declare Function GetWindowLong Lib "user32" _
  19. Alias "GetWindowLongA" (ByVal hwnd As Long, _
  20. ByVal nIndex As Long) As Long
  21. Private Declare Function SetWindowPos Lib "user32" _
  22. (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
  23. ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
  24. ByVal cy As Long, ByVal wFlags As Long) As Long
  25.  
  26. Sub HideAccessCloseButton()
  27.  
  28.    Dim lngStyle As Long
  29.  
  30.    lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
  31.    lngStyle = lngStyle And Not WS_SYSMENU
  32.    Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
  33.    Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
  34.  
  35. End Sub
What do I need to do to fix this? I get it on all 3 Private Declare Functions.
1 Week Ago #1

✓ answered by twinnyfo

I found it!

Here is the entire code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare PtrSafe Function _
  5.     GetSystemMenu _
  6.     Lib "user32" ( _
  7.     ByVal hwnd As Long, _
  8.     ByVal bRevert As Long) _
  9.     As Long
  10.  
  11. Public Declare PtrSafe Function _
  12.     EnableMenuItem _
  13.     Lib "user32" ( _
  14.     ByVal hMenu As Long, _
  15.     ByVal wIDEnableItem As Long, _
  16.     ByVal wEnable As Long) _
  17.     As Long
  18.  
  19. '******************************************************************************
  20. '* This Procedure enables or disables the 'Close' button on the Access Window *
  21. '* This prevents Users from accidentally closing the DB when they really      *
  22. '* only want to close a Report in Preview Mode.                               *
  23. '******************************************************************************
  24. Public Sub AccessCloseButtonEnabled(fEnabled As Boolean)
  25. On Error Resume Next
  26.  
  27.     Const clngMF_ByCommand  As Long = &H0&
  28.     Const clngMF_Grayed     As Long = &H1&
  29.     Const clngSC_Close      As Long = &HF060&
  30.  
  31.     Dim lngWindow   As Long
  32.     Dim lngMenu     As Long
  33.     Dim lngFlags    As Long
  34.  
  35.     lngWindow = Application.hWndAccessApp
  36.     lngMenu = GetSystemMenu(lngWindow, 0)
  37.  
  38.     If fEnabled Then
  39.         lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  40.     Else
  41.         lngFlags = clngMF_ByCommand Or clngMF_Grayed
  42.     End If
  43.  
  44.     Call EnableMenuItem(hMenu:=lngMenu, _
  45.                         wIDEnableItem:=clngSC_Close, _
  46.                         wEnable:=lngFlags)
  47.  
  48. End Sub

Share this Question
Share on Google+
9 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,184
DJ - Try this instead. It simply disables the button (or enables it).

Much easier to use. Put it in a standalone module and call it from anywhere else in your project.

Expand|Select|Wrap|Line Numbers
  1. '******************************************************************************
  2. '* This Procedure enables or disables the 'Close' button on the Access Window *
  3. '* This prevents Users from accidentally closing the DB when they really      *
  4. '* only want to close a Report in Preview Mode.                               *
  5. '******************************************************************************
  6. Public Sub AccessCloseButtonEnabled(fEnabled As Boolean)
  7. On Error Resume Next
  8.  
  9.     Const clngMF_ByCommand  As Long = &H0&
  10.     Const clngMF_Grayed     As Long = &H1&
  11.     Const clngSC_Close      As Long = &HF060&
  12.  
  13.     Dim lngWindow   As Long
  14.     Dim lngMenu     As Long
  15.     Dim lngFlags    As Long
  16.  
  17.     lngWindow = Application.hWndAccessApp
  18.     lngMenu = GetSystemMenu(lngWindow, 0)
  19.  
  20.     If fEnabled Then
  21.         lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  22.     Else
  23.         lngFlags = clngMF_ByCommand Or clngMF_Grayed
  24.     End If
  25.  
  26.     Call EnableMenuItem(hMenu:=lngMenu, _
  27.                         wIDEnableItem:=clngSC_Close, _
  28.                         wEnable:=lngFlags)
  29.  
  30. End Sub
I don't think it requires any additional declarations. Let me know if this works.
1 Week Ago #2

100+
P: 144
The code itself compiles, but my callout does not.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.     Call AccessCloseButtonEnabled
  4.  
  5. End Sub
Compile error: Argument not optional.
1 Week Ago #3

twinnyfo
Expert Mod 2.5K+
P: 3,184
Argument again! Iíll ask the mods to let you figure this one out for now.

Easy solution. Just read some of your previous posts.
1 Week Ago #4

100+
P: 144
Your right it was an easy solution, so I got that fixed, still doesn't compile, but do to another spot in the public function

Expand|Select|Wrap|Line Numbers
  1. lngMenu = GetSystemMenu(lngWindow, 0)
Throws an error of:

Compile error:
Sub or function not defined

Any Idea on why this is doing this?

If I comment this out I get an error here:

Expand|Select|Wrap|Line Numbers
  1. Call EnableMenuItem(hMenu:=lngMenu, _
  2.                         wIDEnableItem:=clngSC_Close, _
  3.                         wEnable:=lngFlags)
Same error as above.
1 Week Ago #5

twinnyfo
Expert Mod 2.5K+
P: 3,184
This should do it. I couldnít remember the other declaration associated with it. But, you did a good job of troubleshooting to identify where the problem was. All part of the process.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Declare PtrSafe Function GetSystemMenu Lib "user32" ( _
  5.     ByVal hwnd As Long, _
  6.     ByVal bRevert As Long) _
  7.     As Long
  8.  
  9. '******************************************************************************
  10. '* This Procedure enables or disables the 'Close' button on the Access Window *
  11. '* This prevents Users from accidentally closing the DB when they really      *
  12. '* only want to close a Report in Preview Mode.                               *
  13. '******************************************************************************
  14. Public Sub AccessCloseButtonEnabled(fEnabled As Boolean)
  15. On Error Resume Next
  16.  
  17.     Const clngMF_ByCommand  As Long = &H0&
  18.     Const clngMF_Grayed     As Long = &H1&
  19.     Const clngSC_Close      As Long = &HF060&
  20.  
  21.     Dim lngWindow   As Long
  22.     Dim lngMenu     As Long
  23.     Dim lngFlags    As Long
  24.  
  25.     lngWindow = Application.hWndAccessApp
  26.     lngMenu = GetSystemMenu(lngWindow, 0)
  27.  
  28.     If fEnabled Then
  29.         lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  30.     Else
  31.         lngFlags = clngMF_ByCommand Or clngMF_Grayed
  32.     End If
  33.  
  34.     Call EnableMenuItem(hMenu:=lngMenu, _
  35.                         wIDEnableItem:=clngSC_Close, _
  36.                         wEnable:=lngFlags)
  37.  
  38. End Sub
1 Week Ago #6

twinnyfo
Expert Mod 2.5K+
P: 3,184
I will have to get back to this on Monday. I am missing a function that I have at work.
1 Week Ago #7

twinnyfo
Expert Mod 2.5K+
P: 3,184
I found it!

Here is the entire code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare PtrSafe Function _
  5.     GetSystemMenu _
  6.     Lib "user32" ( _
  7.     ByVal hwnd As Long, _
  8.     ByVal bRevert As Long) _
  9.     As Long
  10.  
  11. Public Declare PtrSafe Function _
  12.     EnableMenuItem _
  13.     Lib "user32" ( _
  14.     ByVal hMenu As Long, _
  15.     ByVal wIDEnableItem As Long, _
  16.     ByVal wEnable As Long) _
  17.     As Long
  18.  
  19. '******************************************************************************
  20. '* This Procedure enables or disables the 'Close' button on the Access Window *
  21. '* This prevents Users from accidentally closing the DB when they really      *
  22. '* only want to close a Report in Preview Mode.                               *
  23. '******************************************************************************
  24. Public Sub AccessCloseButtonEnabled(fEnabled As Boolean)
  25. On Error Resume Next
  26.  
  27.     Const clngMF_ByCommand  As Long = &H0&
  28.     Const clngMF_Grayed     As Long = &H1&
  29.     Const clngSC_Close      As Long = &HF060&
  30.  
  31.     Dim lngWindow   As Long
  32.     Dim lngMenu     As Long
  33.     Dim lngFlags    As Long
  34.  
  35.     lngWindow = Application.hWndAccessApp
  36.     lngMenu = GetSystemMenu(lngWindow, 0)
  37.  
  38.     If fEnabled Then
  39.         lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  40.     Else
  41.         lngFlags = clngMF_ByCommand Or clngMF_Grayed
  42.     End If
  43.  
  44.     Call EnableMenuItem(hMenu:=lngMenu, _
  45.                         wIDEnableItem:=clngSC_Close, _
  46.                         wEnable:=lngFlags)
  47.  
  48. End Sub
1 Week Ago #8

ADezii
Expert 5K+
P: 8,619
Expand|Select|Wrap|Line Numbers
  1. Public Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As LongPtr, ByVal bRevert As Long) As LongPtr
  2. Public Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Expand|Select|Wrap|Line Numbers
  1. Public Sub AccessCloseButtonEnabled(pfEnabled As Boolean)
  2. On Error Resume Next
  3. Const clngMF_ByCommand As Long = &H0&
  4. Const clngMF_Grayed As Long = &H1&
  5. Const clngSC_Close As Long = &HF060&
  6. Dim lngWindow As Long
  7. Dim lngMenu As Long
  8. Dim lngFlags As Long
  9.  
  10. lngWindow = Application.hWndAccessApp
  11. lngMenu = GetSystemMenu(lngWindow, 0)
  12.  
  13. If pfEnabled Then
  14.   lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  15. Else
  16.   lngFlags = clngMF_ByCommand Or clngMF_Grayed
  17. End If
  18.  
  19. Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
  20. End Sub
Expand|Select|Wrap|Line Numbers
  1. Call AccessCloseButtonEnabled(True)
Expand|Select|Wrap|Line Numbers
  1. Call AccessCloseButtonEnabled(False)
1 Week Ago #9

100+
P: 144
Thanks everyone, works perfectly with no issues. You guys are the best. Hope everyone was a great week.
1 Week Ago #10

Post your reply

Sign in to post your reply or Sign up for a free account.