Adding MsgBox to a form

  • Thread starter Thread starter troublecat12
  • Start date Start date
T

troublecat12

I am a novice Access user. I would like to build a msgbox On Enter for a
check box field and also for a text box in my form.

The message would read,"Are you sure you want to update this field?"

What is the simplest way to do so?

Thanks,
Mary
 
You don't want to use the Enter event because it will pop up every time you
enter the control. You only want to ask if there has been a change to the
control's value.
Use the control's Before Update event:

Private Sub chkPlease_BeforeUpdate(Cancel As Integer)

If Msgbox("Are you sure you want to update this field?", vbQuestion +
vbYesNo + vbDefaultButton2) = vbNo Then
Cancel = True
End If

End Sub
 
I keep playing around with this, but when I cut and paste exactly what you
wrote, no message box appears, and when I modify it to (see below) based on
what was in the original code, I get a syntax error.:

Private Sub background_check_BeforeUpdate(Cancel As Integer)

If Msgbox("Are you sure you want to update this field?", vbQuestion +
vbYesNo + vbDefaultButton2) = vbNo Then
Cancel = True
End If

End Sub

As I said, I'm a beginner and this is the first time I've gone into the code
at all.
 
I am a novice Access user. I would like to build a msgbox On Enter for a
check box field and also for a text box in my form.

The message would read,"Are you sure you want to update this field?"

What is the simplest way to do so?

Thanks,
Mary

Just one caution - Dave's BeforeUpdate code is the way to do this, but I have
to be concerned: do you WANT to do this? If users routinely get nagged by
messages like this, they'll pretty quickly tune out and just unthinkingly
click OK: "Yes, dammit, I updated it because I wanted to update it!"

Add the code if you want, but do be aware of the downside!

You may also want to modify the code to avoid the message if this is the new
record:

If Not Me.NewRecord Then
MsgBox...
End If
 
It probably is because of how you put it in you form module.
The correct way to do it is to open the form in design view, select the
control you want, open the properties sheet, and select the Events tab.
Click on the button with the 3 dots to the right of the Before Update event
box. When prompted, select Code builder. The VBE will open with the cursor
in the event. Paste the code there.

Also, John Vinson has an excellent point.
 
Back
Top