Talismanic
Registered User.
- Local time
- Today, 18:01
- Joined
- May 25, 2000
- Messages
- 377
I have a control that needs to stop a person from entering a employee number that is not on file. I have a dcount to do that part of it and a message that warns the user that the number is not valid.
Now I want to force the focus back to the employee number control and clear the wrong data out of it when it happens. This is what I have:
I can get it to work (partially) if I have the code like this but that allows the user to hit cancel and go on. However when OK was pressed the focus was set back to the employee number.
Now I want to force the focus back to the employee number control and clear the wrong data out of it when it happens. This is what I have:
Code:
Private Sub EmployeeNumber_BeforeUpdate(Cancel As Integer)
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim Answer As Variant
If DCount("[LastName]", "EmployeeList", "[EmployeeNumber]= " & _
Me!EmployeeNumber) = 0 Then
strMsg = "Please try a different number"
strTitle = "Invalid Employee Number."
intStyle = vbOKOnly + vbInformation
Answer = MsgBox(strMsg, intStyle, strTitle)
If Answer = vbOKOnly Then Cancel = True
End If
End Sub
I can get it to work (partially) if I have the code like this but that allows the user to hit cancel and go on. However when OK was pressed the focus was set back to the employee number.
Code:
intStyle = vbOkCancel + vbInformation
If answer = vbCancel then Cancel = True
Exit Sub