×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Warning Message for change of data in a Form Field
3

Warning Message for change of data in a Form Field

Warning Message for change of data in a Form Field

(OP)
I would like to have a popup message box that warns the user that data has been changed and they must verify the change or cancel the if the change was in error. This is the code I have:

Private Sub LastName_BeforeUpdate(Cancel As Integer)

If MsgBox("Last Name has been changed, is this change correct ?", vbYesNo) = vbNo Then
Me!LastName.Undo

End If
End Sub


The VB editor window highlights "Me!LastName.Undo

What could be wrong with code?

Thanks for your help!

RE: Warning Message for change of data in a Form Field

Me.LastName.Undo
However, Undo will not work.
Use instead:

CODE -->

Private strLastName

Private Sub LastName_Enter()
strLastName = Me.LastName.Text
End Sub

Private Sub LastName_Exit(Cancel As Integer)
If MsgBox("Last Name has been changed, is this change correct ?", vbYesNo) = vbNo Then
    Me.LastName.Text = strLastName
End If
End Sub 
You can use MsgBox with Yes-No-Cancel buttons and cancel message leaving user in the textbox after Cancel=1.

combo

RE: Warning Message for change of data in a Form Field

"MsgBox with Yes-No-Cancel " MZTools has a nice feature to create any message box and code, so for combo's suggestion it would be:

CODE

Select Case MsgBox("Last Name has been changed, is this change correct?", _
    vbYesNoCancel Or vbQuestion Or vbDefaultButton2, "Is It Correct?")

    Case vbYes
        
    Case vbNo

    Case vbCancel

End Select 

I always set the default button in the MsgBox to the 'safe' response.


---- Andy

There is a great need for a sarcasm font.

RE: Warning Message for change of data in a Form Field

Assuming LastName is bound...

CODE

Me!LastName = Me!LastName.OldValue 

... also I always forget whether Oldvalue is appropriate before Update or After update so there may be a timing issue.

RE: Warning Message for change of data in a Form Field

(OP)
Thank you everyone for your suggestions! Each one helped!
You guys are awesome

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close