Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning Message for change of data in a Form Field 3

Status
Not open for further replies.

monkeysee

Programmer
Sep 24, 2002
201
0
0
US
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
[highlight #FCE94F]Me!LastName.Undo[/highlight]

End If
End Sub


The VB editor window highlights "Me!LastName.Undo

What could be wrong with code?

Thanks for your help!
 
[tt]Me.LastName.Undo[/tt]
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
 
MsgBox with Yes-No-Cancel " [link MZTools.com]MZTools[/url] 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.
 
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.
 
Thank you everyone for your suggestions! Each one helped!
You guys are awesome
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top