CraigDiver
New member
- Local time
- Today, 22:39
- Joined
- Aug 4, 2006
- Messages
- 6
I am using the lostfocus event to validate unbound text boxes on a form. The first one (Text121_LostFocus) works perfectly, then the second lostfocus event (Text123_LostFocus) works initially then stops reacting for no apparent reason. If I copy the code and repaste it in it works again. Pleeaaasseee help! (Access 2000 ver9.0.2720).
Code:
Private Sub Text121_LostFocus()
' extra error trap to prevent null value
If IsNull(Text121.Value) Then
MsgBox "Please enter model type and serial number"
Text121.SetFocus
Exit Sub
End If
' capture model & type entered, prepare to send for validation
Dim McType As String, McSer As String
McType = Left(Text121, 3)
If Len(Text121) = 8 Then McSer = Right(Text121, 5) _
Else McSer = "0" & Right(Text121, 4)
' send for validation
If McValid(McType & McSer, "N") = False Then
Text121.Value = ""
Else:
Text121.Value = McType & McSer
Text123.Enabled = True
Text123.SetFocus
Text121.Enabled = False
End If
End Sub
Private Sub Text123_LostFocus()
Dim TextEntry As String
TextEntry = Text123.Value
If TextEntry <> "0" And Len(TextEntry) = 1 Then TextEntry = "0000" & TextEntry
If TextEntry <> "0" And Len(TextEntry) = 2 Then TextEntry = "000" & TextEntry
If TextEntry <> "0" And Len(TextEntry) = 3 Then TextEntry = "00" & TextEntry
If TextEntry <> "0" And Len(TextEntry) = 4 Then TextEntry = "0" & TextEntry
Text123.Value = TextEntry
If TextEntry <= Right(Text121.Value, 5) And TextEntry <> "0" Then
MsgBox TextEntry & ", " & Right(Text121.Value, 5) & "Not allowed"
Text123.Value = ""
Else:
Text125.Enabled = True
Text125.SetFocus
Text123.Enabled = False
End If
End Sub