I'm having a problem with the lost focus. I have 3 textboxes. I just want to scan in information. The last textbox will save my information and cycle me back to the first textbox. My problem is that once I scan something invalid it will give me a error. The second time I scan the information in, it does a search and retrieves information. I don't know why. Also my criteria doesn't work correctly. My criteria is suppose to check the length of the inputted information. It works only sometimes. Can someone help me with this. Or have another way of doing this. I have encluded code below
thanks
Option Compare Database
Option Explicit
Private Sub Form_Load()
Me.Form.Textbox1 = Null
Me.Form.Textbox2 = Null
Me.Form.Textbox3 = Null
Me.Textbox1.SetFocus
End Sub
Private Sub Textbox1_LostFocus()
If Not IsNull(Textbox1) Then
If Len([Textbox1]) = 9 Then
Me.Textbox2.SetFocus
Else
MsgBox "This is an invalid Textbox1, please reenter textbox1", 48, "Error"
Me.Form.Textbox1 = Null
Me.Textbox1.SetFocus
End If
End If
End Sub
Private Sub Textbox2_LostFocus()
If Not IsNull(Textbox2) Then
If Len([Textbox2]) >= 12 Then
Me.Textbox3.SetFocus
Else
MsgBox "This is an invalid Serial Number, please reenter Serial Number", 48, "Error"
Me.Form.Textbox2 = Null
Me.Textbox2.SetFocus
End If
End If
End Sub
Private Sub Textbox3_LostFocus()
Dim dbsa As Database, rst As Variant, num As Variant
If Not IsNull(Textbox3) Then
If Len([Textbox3]) = 9 Then
Else
MsgBox "This is an invalid Serial Number, please reenter Serial Number", 48, "Error"
Me.Form.Textbox3 = Null
Me.Textbox3.SetFocus
End If
End If
If Not IsNull(Me.Form.Textbox1) And Not IsNull(Me.Form.Textbox2) And Not IsNull(Me.Form.Textbox3) Then
Set dbsa = CurrentDb
Set rst = dbsa.OpenRecordset("current_table"
rst.AddNew
rst![Textbox1] = Me.Form.Textbox1
rst![Textbox2] = Me.Form.Textbox2
rst![Textbox3] = Me.Form.Textbox3
rst.Update
rst.Close
Else
MsgBox "There is no Data to save", 48, " Error"
Me.Textbox1.SetFocus
End If
Me.Form.Textbox1 = Null
Me.Form.Textbox2 = Null
Me.Form.Textbox3 = Null
Me.Textbox1.SetFocus
End Sub
Private Sub Save_Click()
End Sub
thanks
Option Compare Database
Option Explicit
Private Sub Form_Load()
Me.Form.Textbox1 = Null
Me.Form.Textbox2 = Null
Me.Form.Textbox3 = Null
Me.Textbox1.SetFocus
End Sub
Private Sub Textbox1_LostFocus()
If Not IsNull(Textbox1) Then
If Len([Textbox1]) = 9 Then
Me.Textbox2.SetFocus
Else
MsgBox "This is an invalid Textbox1, please reenter textbox1", 48, "Error"
Me.Form.Textbox1 = Null
Me.Textbox1.SetFocus
End If
End If
End Sub
Private Sub Textbox2_LostFocus()
If Not IsNull(Textbox2) Then
If Len([Textbox2]) >= 12 Then
Me.Textbox3.SetFocus
Else
MsgBox "This is an invalid Serial Number, please reenter Serial Number", 48, "Error"
Me.Form.Textbox2 = Null
Me.Textbox2.SetFocus
End If
End If
End Sub
Private Sub Textbox3_LostFocus()
Dim dbsa As Database, rst As Variant, num As Variant
If Not IsNull(Textbox3) Then
If Len([Textbox3]) = 9 Then
Else
MsgBox "This is an invalid Serial Number, please reenter Serial Number", 48, "Error"
Me.Form.Textbox3 = Null
Me.Textbox3.SetFocus
End If
End If
If Not IsNull(Me.Form.Textbox1) And Not IsNull(Me.Form.Textbox2) And Not IsNull(Me.Form.Textbox3) Then
Set dbsa = CurrentDb
Set rst = dbsa.OpenRecordset("current_table"
rst.AddNew
rst![Textbox1] = Me.Form.Textbox1
rst![Textbox2] = Me.Form.Textbox2
rst![Textbox3] = Me.Form.Textbox3
rst.Update
rst.Close
Else
MsgBox "There is no Data to save", 48, " Error"
Me.Textbox1.SetFocus
End If
Me.Form.Textbox1 = Null
Me.Form.Textbox2 = Null
Me.Form.Textbox3 = Null
Me.Textbox1.SetFocus
End Sub
Private Sub Save_Click()
End Sub