Help with undo, please.

Wegets7

Registered User.
Local time
Today, 15:54
Joined
Oct 18, 2004
Messages
40
I have a form with a combo box that notifies the user when they are changing a pre-existing record. I would like when the user click on the negitive/no button on the message box that the change is reversed. However I get a runtime error telling me that Undo is not available now.

Thanks
This is the code.

Code:
Private Sub FK_CopyKey_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_FK_CopyKey_BeforeUpdate

    Const strMessage1 As String = "Are you sure you want to change this record?"
    Const strTitle As String = "Changing Records?"
    Dim bytResponse As Byte
    Const intStyle As Integer = vbInformation + vbYesNo + vbDefaultButton2
    Dim Count As Integer
        
    If Not Me.NewRecord Then
        bytResponse = MsgBox(strMessage1, intStyle, strTitle)
    Else: bytResponse = vbYes
    End If
 
    If bytResponse = vbNo Then
        Cancel = True
        DoCmd.RunCommand acCmdUndo
    End If
    Exit Sub

Err_FK_CopyKey_BeforeUpdate:
    If Err.Number <> 3021 Then
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    End If

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom