LostFocus driving me insane

CraigDiver

New member
Local time
Today, 03:56
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).:confused:

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
 
Is that an exact copy of your code? if so, then look at the section here
Code:
If TextEntry <= Right(Text121.Value, 5) And TextEntry <> "0" Then
            MsgBox TextEntry & ", " & Right(Text121.Value, 5) & "Not allowed"
            Text123.Value = ""
            Else: 'here is a label, not an else statement, remove the :
            Text125.Enabled = True
            Text125.SetFocus
            Text123.Enabled = False
        End If

Other than that, I don't know. I sometimes have trouble in my db when a control 'disassociates' itself with the code in the module. The way I normally fix it is to reset the On event in the controls properties to [event procedure]. It's never happened in my actual released versions, so I think its a slight bug that occurs with frequent editing of the code modules :)
 
workmad3 said:
Else: 'here is a label, not an else statement, remove the :[/code]

Thank you so much, that fixed the problem.

I'm very grateful:o
 

Users who are viewing this thread

Back
Top Bottom