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
 
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!
 
Top