ChronicFear
Registered User.
- Local time
- Yesterday, 18:44
- Joined
- Oct 18, 2007
- Messages
- 66
Hi,
I was testing out some code I found on this website and other MVP locations to hide all the menus and disable the Access close button. It would then make sure to reverse before closing the database. I also created a button to bring everything back.
This worked like a charm for about an hour. Then I came back from lunch and Access has started loading my switchboard minimized in the upper left corner of the screen and giving me no menu options. The button I created brings back the database window (minimized) and the menu bar, but not everything. Also, when I hold shift to load it opens Access, but just gives be a blank screen. No database window, no menus, no nothing.
The database is housed on a closed system, so I know nobody could have messed with it while I was at lunch. I don't understand why it would work repeatedly on opening and closing and then suddenly not work anymore. This problem occurs with all previous versions of my database (that include none of the hiding code), as well as unrelated databases, which indicates it's some sort of setting saved in Access itself.
I would really appreciate your help. Hiding code is below:
This runs when the database is opened:
This is the function that is called:
This runs when the user closes the database:
I was testing out some code I found on this website and other MVP locations to hide all the menus and disable the Access close button. It would then make sure to reverse before closing the database. I also created a button to bring everything back.
This worked like a charm for about an hour. Then I came back from lunch and Access has started loading my switchboard minimized in the upper left corner of the screen and giving me no menu options. The button I created brings back the database window (minimized) and the menu bar, but not everything. Also, when I hold shift to load it opens Access, but just gives be a blank screen. No database window, no menus, no nothing.
The database is housed on a closed system, so I know nobody could have messed with it while I was at lunch. I don't understand why it would work repeatedly on opening and closing and then suddenly not work anymore. This problem occurs with all previous versions of my database (that include none of the hiding code), as well as unrelated databases, which indicates it's some sort of setting saved in Access itself.
I would really appreciate your help. Hiding code is below:
This runs when the database is opened:
Code:
'Dim I As Integer
For I = 1 To CommandBars.Count
CommandBars(I).Enabled = False
Next I
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
Call SetEnabledState(False)
This is the function that is called:
Code:
Option Compare Database
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
Public Function SetEnabledState(blnState As Boolean)
Call CloseButtonState(blnState)
Call ExitMenuState(blnState)
End Function
'Disable the Menu Option
Sub ExitMenuState(blnExitState As Boolean)
Application.CommandBars("File").Controls("Exit").Enabled = blnExitState
End Sub
'Disable the Close Button Option
Sub CloseButtonState(boolClose As Boolean)
Dim hWnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim result As Long
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If
result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Sub
This runs when the user closes the database:
Code:
Private Sub btnExitDatabase_Click()
If MsgBox("Are you sure you want to exit the database?", vbYesNo, "PFS National Credit Center Database") = vbYes Then
Do
loopcount = loopcount + 1
For Each frm In Application.Forms
DoCmd.Close acForm, frm.Name, acSaveNo
Next frm
formcount = Application.Forms.Count
Loop Until formcount = 0
Call SetEnabledState(True)
Application.Quit (acQuitSaveAll)
Else
Cancel = True
End If
End Sub