0
0 1
I have this code behind a label called "Cancel":
Private Sub lblCancel_Click()
If Me.Dirty = True Then
If MsgBox("This will undo all of the changes you made to this
record. " & _
Chr(13) & Chr(13) & "Continue?", vbYesNo + vbQuestion, "Undo
Changes") = vbNo Then
Cancel = True
Else
Me.Undo
End If
End If
End Sub
It works fine. But I'd like to reuse this for several forms, so I
tried to move it to a Global Module and call it from each form with
"CancelEventRecord." As in:
Public Sub CancelEventRecord()
Dim MyForm As Form
Set MyForm = Screen.ActiveForm
If MyForm.Dirty = True Then
If MsgBox("This will undo all of the changes you made to this
record. " & _
Chr(13) & Chr(13) & "Continue?", vbYesNo + vbQuestion, "Undo
Changes") = vbNo Then
Cancel = True
Else
MyForm.Undo
End If
End If
But this gives me a "variable not defined error," and highlights the
Cancel = True line. Any suggestions?
Thank you.
Private Sub lblCancel_Click()
If Me.Dirty = True Then
If MsgBox("This will undo all of the changes you made to this
record. " & _
Chr(13) & Chr(13) & "Continue?", vbYesNo + vbQuestion, "Undo
Changes") = vbNo Then
Cancel = True
Else
Me.Undo
End If
End If
End Sub
It works fine. But I'd like to reuse this for several forms, so I
tried to move it to a Global Module and call it from each form with
"CancelEventRecord." As in:
Public Sub CancelEventRecord()
Dim MyForm As Form
Set MyForm = Screen.ActiveForm
If MyForm.Dirty = True Then
If MsgBox("This will undo all of the changes you made to this
record. " & _
Chr(13) & Chr(13) & "Continue?", vbYesNo + vbQuestion, "Undo
Changes") = vbNo Then
Cancel = True
Else
MyForm.Undo
End If
End If
But this gives me a "variable not defined error," and highlights the
Cancel = True line. Any suggestions?
Thank you.