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

How can disable window close button for an MDB file?

P: 23

How can disable window close button for an MDB file. because when a user closes application by clicking on window close button (right top corner), unsaved & incomplete data on the form gets saved in respective table. i want to prevent this from happening.

plz give me a good suggestion

thanx a lot in advance.
Dec 25 '13 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 5,397
without a lot of work, you don't.

instead you prevent a form from closing as I explained to you here:

These two questions are basically the same and such threads are occationally deleted on the grounds of double posting.
Dec 25 '13 #2

Expert Mod 15k+
P: 31,494
Sometimes the rules about double-posting and having a single topic per thread can be confusing.

However, whether or not you realise it, these questions do overlap (This one and the one linked in Z's post). The answer is also in that linked thread. Simply have a form that is open and that has Cancel = True in the Form_Unload() event procedure. Handle with care though, of course, as if it is always True then the database will never close!
Dec 26 '13 #3

P: 547
i use this "call" in the "load" event of the startup form and it seems to work fine. Hope it helps?

Expand|Select|Wrap|Line Numbers
  1. Call SetEnabledState(False)
The "Disable X" module code to save is:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
  5.     ByVal bRevert As Long) As Long
  7. Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
  8.     Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
  10. Const MF_GRAYED = &H1&
  11. Const MF_BYCOMMAND = &H0&
  12. Const SC_CLOSE = &HF060&
  14. Public Function SetEnabledState(blnState As Boolean)
  15.     Call CloseButtonState(blnState)
  16.     'Call ExitMenuState(blnState)
  17. End Function
  19. 'Disable the Menu Option
  20. 'Sub ExitMenuState(blnExitState As Boolean)
  21.    ' Application.CommandBars("File").Controls("Exit").Enabled = blnExitState
  22. 'End Sub
  24. 'Disable the Close Button Option
  25. Sub CloseButtonState(boolClose As Boolean)
  26.     Dim hWnd As Long
  27.     Dim wFlags As Long
  28.     Dim hMenu As Long
  29.     Dim result As Long
  31.     hWnd = Application.hWndAccessApp
  32.     hMenu = GetSystemMenu(hWnd, 0)
  33.     If Not boolClose Then
  34.         wFlags = MF_BYCOMMAND Or MF_GRAYED
  35.     Else
  36.         wFlags = MF_BYCOMMAND And Not MF_GRAYED
  37.     End If
  39.     result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
  40. End Sub
Dec 29 '13 #4

Expert Mod 15k+
P: 31,494
Neels, This is a dead thread (I'll close it now as possibly I should have earlier).

The linked thread has a perfectly adequate and appropriate solution that is a single line of code within an event procedure.
Dec 29 '13 #5

This discussion thread is closed

Replies have been disabled for this discussion.