P
Phil Hood
Hello,
I wonder if anyone can help with this problem.
When I create the following event procedure, the code
works as expected i.e the attempt to update the combo box
is 'undone' and the original value is restored.
-----------------------------------------------
Private Sub Combo65_BeforeUpdate(Cancel As Integer)
Dim RetValue As Integer
RetValue = MsgBox("This employee has already been selected
for the team so cannot be added. Please select again.",
vbApplicationModal, "Warning")
If RetValue = vbOK Or vbCancel Then
Screen.ActiveControl.Undo
Cancel = True
End If
End If
End Function
-----------------------------------------------
However, when I create it as a public function (because
there are a number of combo boxes on the form and I want
to make it accessible to all), I get two errors:
1. Compile error: Variable not defined (Cancel)
2. The value in the combo box is not restored to its
orginal value
-----------------------------------------------
Public Function AddEmpeeToTeam()
Dim RetValue As Integer
RetValue = MsgBox("This employee has already been selected
for the team so cannot be added. Please select again.",
vbApplicationModal, "Warning")
If RetValue = vbOK Or vbCancel Then
Screen.ActiveControl.Undo
Cancel = True
End If
End If
End Function
I wonder if anyone can help with this problem.
When I create the following event procedure, the code
works as expected i.e the attempt to update the combo box
is 'undone' and the original value is restored.
-----------------------------------------------
Private Sub Combo65_BeforeUpdate(Cancel As Integer)
Dim RetValue As Integer
RetValue = MsgBox("This employee has already been selected
for the team so cannot be added. Please select again.",
vbApplicationModal, "Warning")
If RetValue = vbOK Or vbCancel Then
Screen.ActiveControl.Undo
Cancel = True
End If
End If
End Function
-----------------------------------------------
However, when I create it as a public function (because
there are a number of combo boxes on the form and I want
to make it accessible to all), I get two errors:
1. Compile error: Variable not defined (Cancel)
2. The value in the combo box is not restored to its
orginal value
-----------------------------------------------
Public Function AddEmpeeToTeam()
Dim RetValue As Integer
RetValue = MsgBox("This employee has already been selected
for the team so cannot be added. Please select again.",
vbApplicationModal, "Warning")
If RetValue = vbOK Or vbCancel Then
Screen.ActiveControl.Undo
Cancel = True
End If
End If
End Function