Problem calling a sub routine on data change

mlai08

Registered User.
Local time
Today, 05:43
Joined
Dec 20, 2007
Messages
110
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 :confused:
 
You could modify the sub to a function that returns a Boolean value. Then in your individual events:

Cancel = ContAlert()
 
You could modify the sub to a function that returns a Boolean value. Then in your individual events:

Cancel = ContAlert()


I know if should be something simple. Thanks for your enlightenment. :D
 
No problemo; post back if you get stuck.
 

Users who are viewing this thread

Back
Top Bottom