The following codes work fine - it allows users to choose OK to allow change on the form field and reject change by choosing Cancel.
Private Sub ContStartDate_Dirty(Cancel As Integer)
Dim strMsg As String
Dim intchoice As Integer
strMsg = "XYZ"
intchoice = MsgBox(strMsg, vbOKCancel, "Message Alert")
If intchoice = vbOK Then 'Bypass alert to accept change
Cancel = False
Exit Sub
Else
intchoice = vbCancel 'Discard change
Cancel = True
End If
End Sub
However, I need to run the same codes for a number of fields on the form and don't really want to repeat the codes on the respective fields. I tried to put the codes in a sub routine and let field event to call the routine but it does not work.
Private Sub ContStartDate_Dirty(Cancel As Integer)
Call ContAlert
End Sub
Private Sub ContAlert(Cancel As Integer)
Dim strMsg As String
Dim intchoice As Integer
strMsg = "XYZ"
intchoice = MsgBox(strMsg, vbOKCancel, "Message Alert")
If intchoice = vbOK Then 'Bypass alert to accept change
Cancel = False
Exit Sub
Else
intchoice = vbCancel 'Discard change
Cancel = True
End If
End Sub
I think the issue is I can not pass the Cancel status from the sub routine back to the calling event. Wonder if anyone can help me with this?
Thanks
Private Sub ContStartDate_Dirty(Cancel As Integer)
Dim strMsg As String
Dim intchoice As Integer
strMsg = "XYZ"
intchoice = MsgBox(strMsg, vbOKCancel, "Message Alert")
If intchoice = vbOK Then 'Bypass alert to accept change
Cancel = False
Exit Sub
Else
intchoice = vbCancel 'Discard change
Cancel = True
End If
End Sub
However, I need to run the same codes for a number of fields on the form and don't really want to repeat the codes on the respective fields. I tried to put the codes in a sub routine and let field event to call the routine but it does not work.
Private Sub ContStartDate_Dirty(Cancel As Integer)
Call ContAlert
End Sub
Private Sub ContAlert(Cancel As Integer)
Dim strMsg As String
Dim intchoice As Integer
strMsg = "XYZ"
intchoice = MsgBox(strMsg, vbOKCancel, "Message Alert")
If intchoice = vbOK Then 'Bypass alert to accept change
Cancel = False
Exit Sub
Else
intchoice = vbCancel 'Discard change
Cancel = True
End If
End Sub
I think the issue is I can not pass the Cancel status from the sub routine back to the calling event. Wonder if anyone can help me with this?
Thanks