Msgbox to confirm changes to specific control

Kregg

Registered User.
Local time
Today, 06:17
Joined
Jul 8, 2013
Messages
41
Hi all! I have a database in which users have the ability to search by last name...nothing fancy there. However, the users continue to forget to click the Find Client button and instead just type what name they are looking for in the LASTNAME control thus changing the record that they are currently in!!!

I am looking for a way to have a msgbox pop up any time the LASTNAME control is changed. I found the code below but this works for the entire record and I don't want them to have to click Yes every time they make change.

Any suggestions?

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Changes have been made to this record." _
        & vbCrLf & vbCrLf & "Do you want to save these changes?" _
        , vbYesNo, "Changes Made...") = vbYes Then
            DoCmd.Save
        Else
            DoCmd.RunCommand acCmdUndo
    End If
End Sub
 
Try the Control Before Update instead of Form Before Update.
 
Try the Control Before Update instead of Form Before Update.

This is moving in the right track. I unfortunately can not get the Undo command to work. I have used the following:

DoCmd.RunCommand acCmdUndo

and

Me.LASTNAME.Undo

The first option brings back an error message and the second simply does not undo the correct. Any suggestions?
 
The Me.LastName.Undo should simply revert the changes made since its old value. But make sure Cancel is set to True first..
Code:
Private Sub LastName_BeforeUpdate(Cancel As Integer)
    If MsgBox("Changes have been made to this record." _
                & vbCrLf & vbCrLf & "Do you want to save these changes?" _
                , vbYesNo, "Changes Made...") = vbNo Then
            [COLOR=Red][B]Cancel = True[/B][/COLOR]
            Me.LastName.Undo
    End If
End Sub
 
The Me.LastName.Undo should simply revert the changes made since its old value. But make sure Cancel is set to True first..
Code:
Private Sub LastName_BeforeUpdate(Cancel As Integer)
    If MsgBox("Changes have been made to this record." _
                & vbCrLf & vbCrLf & "Do you want to save these changes?" _
                , vbYesNo, "Changes Made...") = vbNo Then
            [COLOR=red][B]Cancel = True[/B][/COLOR]
            Me.LastName.Undo
    End If
End Sub

Perfect!!!
 

Users who are viewing this thread

Back
Top Bottom