When the user enters a number that is already in use, it fires a message box with the warning that the number is already being used. The idea then is to reset the focus to the orginal txtRegNumber txt box to try again. the user will probably use the [enter] key to close the message box. However, the ctl.setfocus part of the code seems to have no effect and the cursor ends up in the next txtbox. I am missing something because I have this same problems in several areas.
v.b.
Expand|Select|Wrap|Line Numbers
- 1. Private Sub txtRegNum_AfterUpdate()
- 2. Dim ctl As Control
- 3. Dim varRegNum As Variant
- 4. Set ctl = Me!txtRegNum
- 5. varRegNum = DCount("[RegNum]", "tblAircraft", "[RegNum] = [txtRegNum]")
- 6. MsgBox ("varRegNum = " & varRegNum) ' for my program tracking purposes
- 7. If varRegNum > 0 Then
- 8. MsgBox ("THIS REGISTRATION NUMBER IS ALREADY IN USE.")
- 9. DoCmd.CancelEvent
- 10. ctl.SetFocus
- 11. Else
- 12 Exit Sub
- 13. End If
- 14. Set ctl = Nothing
- 15. End Sub
-Tom