Menus no longer appear, shift gives blank screen

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:
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
 
you could create a blank database and import all the objects from the db causing problems.
Although its probally best not to import the above code until you have sorted the problem out.
 
Last edited:
Try next;
When you open Access with SHIFT button, try to move SCROLL BARS (vertical and horisontal), the database window must be here somewhere.
 
When you open it holding the shift key down, can you click F11 and get anything?
 
Thanks for the responses, guys.

Dennisk - I have not tried importing my database to a new one, but I did try creating a new database and had the same results. This problem also occurs when opening other databases on different servers.

Mstef - There are no scroll bars to move. Simply a blank grey background.

boblarson - Alt+F11 does pull up the code editor, but that's it.


Ok, here's an update. So after trying Alt+F11, I also tried CTRL+F5 (This triggers an autokeys macro that opens a form I created with one button on it. The code behind the button turns the menus back on and brings up the database window. I built this in in case I was at a user's workstation and needed to get to the guts behind their FE.). CTRL+F5 also worked, except that instead of simply bringing up the form with my button, it appears to have also executed the code behind the button as the menus reappeared and both my form and the database window appeared (still minimized in the upper left corner of the screen, though). So I exited the database and reopened it normally and it seems to have loaded correctly.

Any ideas as to what might be going on?
 
Sorry to bring this back up, but the problem is happening again. I've tried importing everything into a new database, but that didn't resolve the problem. Also I tried opening my database on a different computer, and there was no problem, so it appears that the issue is my computer and not the database.

Like last time, after several repeated tries my CTRL+F5 form auto-fired the code behind the button and things are back in order. I'd like, however, to keep the from happening in the future.

Does anyone have other idea on what might be causing this and what I might to do resolve it?

Thanks.
 
do you have some timer event running on the main form, perhaps. The fact that interrupting this with the autokeys macro seems to fix the problem indicates perhaps that access is opening, stuck in a loop of some sort

outside my knowledge to know exactly what though
 
There aren't any loops running. Also, as I mentioned, the problem occurs in different databases containing all sorts of different tables, forms, and code. It also only occurs on my computer. These same databases work just fine on for my co-workers, so this leads me to conclude that it might be my version of Access, but I'm not sure how or why it would become corrupted suddenly when it wasn't even running.
 
Hi, i saw this because it was bumped...but having read the posts, it feels to me everyone has thought of suggestions that can be made from remotely as this board is, sound slike this sort of problem is best sorted on your pc. Refer it to your IT dept, as you said it was your pc and no'one elses.

Is it possible that your set up of Access is different from your users, therefore find out what is different on theirs or what works and replicate it on your own. I know with Excel that hiding menus etc causes issue when opening other spreadsheets unless you code it to replace the menus, but even then that doesn't always work.

Just a thought.
 
just tried to recreate the database using the code snippets and then open other databases i have, i did see some oddities but nothing that wasn't fixed by manually reselecting toolbars etc.. i don't think your closing databae code is fixing everything that was taken away. Also how are you activating the opening sequence of events?
 
Hey Sam. Thanks for taking another look at this. My opening code to hide the menus runs in the Open event for my switchboard. The closing code runs behind the button users must click to save and exit the database.

I'm not really familiar with hiding and unhiding menus, so its entirely possible I've overlooked something. However, as far as I can tell the code I used to hide is exactly the same as the code I'm using to unhide, I just changed False to True, etc. Is there some extra code I would need to add?

What sort of oddities did you encounter on your machine?
 
What sort of oddities did you encounter on your machine?

Like i said i used your code snippets and noticed you didn't replace the CommandBars when closing, my menubar didn't reappear, and a smaller toolbar appeared at the bottom of the screen, but this isn't your database so i may have made a slight error somewhere along the way..

I guess the non show of menu bar is due to again you not setting this:

Code:
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
            DoCmd.SelectObject acTable, , True

But, what does the SelectObject acTable actually do, does it take the focus off of the Database window for the next line

Code:
DoCmd.RunCommand acCmdWindowUnhide

To solve the 1st code example I set the acToolbarNo to Yes so guess my failing but, it was mainly that you weren't replacing the commandbars.

Any help?
 
I guess the non show of menu bar is due to again you not setting this:

Code:
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
            DoCmd.SelectObject acTable, , True

Good catch. I copied the loop that hides the menus and told it to unhide them and put it to run as the user is exiting the database.

But, what does the SelectObject acTable actually do, does it take the focus off of the Database window for the next line

Code:
DoCmd.RunCommand acCmdWindowUnhide

Actually, I don't fully understand what that does. I assumed it was just the bit that brought the database window up. It was some code that I copied in an effort to resolve my problem.

This was helpful, thank you. I'll try living with the new exit code for a bit and see if the error recurrs. Thank you very much for your help!

-CF
 
Chronic..

i noticed that if the commandbar wasn't necessary to display (or to the like) it throws an error, you may want to add in

Code:
on error resume next to the exit routine

just so the system closes without a hitch.

I also thought, maybe you want to identify those menus and commandbars the user has open, store them and replace only them when they exit? just a thought, though the catch all that you have done is fine..
 
i've just noticed that my MenuBar does not want to return!!! no matter what i do. It's ok to build the error routine in, but be careful as you may not pick up important errors...but i said it thinking doing the reverse would bring menus etc back..doesn't appear to be the case ... yet!:D
 
OMG i have so many commandbars opening now...!??! own fault...
 
Haha. Not that I want your computer to break, but I'm glad that the problem is at least replicating itself for you so people don't think I'm crazy! Thanks again for taking a look at this. I'll see if I can come up with some code that only messes with the menus that would have been open instead of the catch-all. The only thing I can see with that approach is that I would still be hiding the MenuBar, which is the problem. But perhaps with identifying it directly it will behave properly!
 
My "solution" thus far has been to open the database, fire both the hide and unhide code, and then close the db. After 5 or 6 times of this exact same action it usually works. :) Hmmm...I suppose admissions like that indicate that I will never be allowed to be a proper db developer. Or even get near computers. :)
 
LOL....i added .visible to the
Code:
Commandbars(I)
code...LOL just goes to show what difference it makes..it should have been .enabled...I instantly got the MenuBar back...

sometimes if you're using a loop like
Code:
For I = 1 to ...
i found using
Code:
Debug.Print CommandBars(I).Name & " " & I
does help to see what is going on and expand your knowledge of the behind the scenes stuff..makes things a bit more transparent..
 

Users who are viewing this thread

Back
Top Bottom