Msgbox to confirm ending session

G

Guest

Hi, I'm new to access and am trying to create a macro that asks the user to
confirm that they wish to end the session of access at that time. I have
tried using the msgbox function but can only get it to come up with the 'ok',
where as I want it to say 'ok' or 'cancel' to stay in the database. Does
anyone have any ideas?

Cheers
Karen
 
S

Steve Schapel

Karen,

There are a couple of approaches you could take here. One would be to
open up an unbound form of your own design, with some command buttons to
give the user choices of where to go from hwere, i.e. to proceed with
exit or not.

Another, as you suggest, is to use the MsgBox() function (in the
Comdition of the macro, not to ne confused with the MsgBox action in the
macro itself). If so, there are numerical values to define the Buttons
argument. For example, 1 means OK/Cancel. 4 means Yes/No. 32 means
Question. So if you do like this...
MsgBox("Really quit now?",36)=6
.... in the Condition of a Quit action in your macro, the message box
will be displayed with Yes and No buttons, plus the question mark icon,
and if the user selects 'Yes' (i.e. value 6) the application will quit.
 
G

Guest

Hi Steve

Thanks for answering my question, and sorry for the late reply......I'm
still a bit stuck on this. I have tried both ways, the form works really
well, but I can't figure out how to 'tie' it to the close button on the
switchboard........have also tried through the code builder and the msgbox
works but it exits access when you click on either 'yes' and 'no' buttons,
obvisously I haven't completed it properly! Could you please have a quick
look at what I have built and see if you can come up with any suggestions
please?

Private Sub Form_Close()
MsgBox "Are you sure you wish to leave Access?", vbYesNo
End Sub
Any help would be appreciated!
Cheers
 
S

Steve Schapel

Karen,

As regards the form-based approach, the Exit/Quit button on your
switchboard needs to open the confirmation form. This would be a simple
OpenForm action if you are usiong a macro. Then, if the confirmation
form has Yes and No buttons on it, the No button would simply have a
macro using the Close action, to close the confirmation form itself,
whereby you end up where you were before, and the Yes button has a macro
with a Quit action to close the database.

The example you gave is a VBA procedure, and not a macro, and as such
does not relate to the information I gave before, which assumed you were
using a macro. Plus the code sample you gave will not cause Access to
close at all, so I am confused about what you are referring to. If I
understand you correctly, and to proceed with the VBA idea, it would
need to be more like this...

Private Sub SomeButton_Click()
If MsgBox("Are you sure you wish to leave Access?", vbYesNo) =
vbYes Then
DoCmd.Quit
End If
End Sub
 
G

Guest

Thanks for the quick reply Steve.........I am a new user and as such the
terminology can get quite confusing at times for me, but I have done as you
suggested and both the form and the vba now work perfectly - yipee, thank you
very much for your help!
 

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