Msg Box Code

  • Thread starter Uschi via AccessMonster.com
  • Start date
U

Uschi via AccessMonster.com

On my form I need a msg box "Back up is STRONGLY recommended after each
session." when the user clicks on the Close Form command button.
Can someone write the code for me?
Also, I would like to know which property to use - On Click or Exit? and why?
Many thanks,
 
M

missinglinq via AccessMonster.com

Assuming you have your own button to close the form, as it sounds, do
something like this:

Private Sub CloseFormCommandButton_Click()

resp = MsgBox("Backup is STRONGLY recommended after each session!",
vbOKOnly, "Warning!")
DoCmd.Close

End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
U

Uschi via AccessMonster.com

Hi,

I put the code on the command button but when I tested it an error message
came up.

The DoCmd.Close was highlighted in yellow. When I deleted the highlighted
portion the code works.

Many thanks for your help.
 
J

John W. Vinson

Hi,

I put the code on the command button but when I tested it an error message
came up.

The DoCmd.Close was highlighted in yellow. When I deleted the highlighted
portion the code works.

Many thanks for your help.

Is this a command button on a Form? If so, it will warn the user and then
immediately close the form, without giving the user a chance to respond!

Try instead

Private Sub CloseFormCommandButton_Click()
Dim resp As Integer

resp = MsgBox("Backup is STRONGLY recommended after each session! Close
anyway?", vbYesNo, "Warning!")
If Resp=vbYes Then
DoCmd.Close acDataForm, Me.Name
End If

End Sub


John W. Vinson [MVP]
 
M

missinglinq via AccessMonster.com

I'm confused, John! My code pops up a warning to remind the user that

"Backup is STRONGLY recommended after each session!"

then closes the form when the OK button is clicked. If you read the original
post, this is what the OP wants! He doesn't want the user to have a choice
about closing, only to be reminded that after closing the form backing up is
a good idea!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

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