enable toolbar code works only half the time.

G

Guest

I have a form called menu that runs at start up and on the onload event
properties of the form:

Private Sub Form_Load()
'==================================================
'DATE: November 10, 2004
'AUTHOR: Todd L. Shillam
'COMMENTS:
'
'1) Removes all Microsoft Access built-in toolbars.
'==================================================

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i

End Sub
'END OF SUBROUTINE

Then I have a command button on the farm called exit:

Private Sub cmdRed_Click()
'DATE: November 10, 2004
'AUTHOR: Todd L. Shillam
'COMMENTS:
'
'1) Enable toolbars.
'==================================================

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = True
Next i

DoCmd.Quit
End Sub

I use the same code from the on load event except I set the CommandBars
(i).Enabled = True

I do this so If I need to modifiy or design the database I can hold the
shift key down and access my menu. However I have to keep going in and
hitting the exit key until I can sucessfully get my menu back.

Question Is the DoCmd.Quit executing in some instances before the
CommandBars(i).Enabled = True is able to execute.

How can I get around this?

Thanks,
 
K

Ken Snell \(MVP\)

Why are you quitting ACCESS (DoCmd.Quit) right after you enable the
toolbars? I don't understand that step's presence if you want to enable the
toolbars while you're working in ACCESS?
 
G

Guest

Good Question: When I start the app I disable the toolbar and menu. keeps my
son from going in and modifying the database objects. However when
executiong the quit button I enable the toolbar and menu so that when I go
into another database I have them both. Holding the shift key down while
starting the application only shows the toolbar and not the menu. Thats why
I enabled it before leaving the app. If you can suggest a better solution I
would greatly appreciate it.

Thanks for your response Ken
 
K

Ken Snell \(MVP\)

Try changing your exit button's click code to this:

Private Sub cmdRed_Click()
'DATE: November 10, 2004
'AUTHOR: Todd L. Shillam

DoCmd.Close acForm, Me.Name, acSaveNo
End Sub


Then add this code to the form's Unload event:

Private Sub Form_Unload(Cancel As Integer)
'1) Enable toolbars.
'==================================================

Dim i As Long
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = True
Next i
DoEvents
Application.Quit
End Sub
 
K

Ken Snell \(MVP\)

Just a guess, but it may be another of the "buggy" behaviors that are
sometimes displayed by DoCmd.Quit method.

In ACCESS, it's recommended that you use Application.Quit to close ACCESS
instead of DoCmd.Quit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top