PDA

View Full Version : FORM - goto first text box if not found



ProteanBeing
09-07-2010, 10:24 AM
I have a pop up entry form that asks for the order number. If found it fills in some read-only data and then follows the tab order to the next text box. However, if the order number is not found a message box appears stating so. The tab order is still followed and goes to the next text box. On not found I want it to go back to the first box for retry. Please help. Code below.

Private Sub txtOrderNumber_AfterUpdate()
With Worksheets("Data")
For Each orderNumber In Range("colOrderNumber")
If orderNumber.Value = txtOrderNumber.Value Then
' lightSwitch turnOn:=True
currentRecord = orderNumber.Row
Me.txtSystemQuantity.Value = .Cells(currentRecord, 8)
Me.txtSystemWeight.Value = .Cells(currentRecord, 11)
Me.txtActualQuantity.Value = .Cells(currentRecord, 16)
Me.txtActualWeight.Value = .Cells(currentRecord, 17)
Me.cboBarrelType.Text = .Cells(currentRecord, 18)

Exit For
End If
If IsEmpty(orderNumber) Then
MsgBox Prompt:=Me.txtOrderNumber.Value, Title:="Record Not Found"
Me.txtOrderNumber.Value = ""
' lightSwitch turnOn:=False
Exit Sub
End If
Next orderNumber
End With
End Sub

Bob Phillips
09-07-2010, 10:41 AM
Is this what you mean?



Private Sub txtOrderNumber_AfterUpdate()
With Worksheets("Data")
For Each orderNumber In Range("colOrderNumber")
If orderNumber.Value = txtOrderNumber.Value Then
' lightSwitch turnOn:=True
currentRecord = orderNumber.Row
Me.txtSystemQuantity.Value = .Cells(currentRecord, 8)
Me.txtSystemWeight.Value = .Cells(currentRecord, 11)
Me.txtActualQuantity.Value = .Cells(currentRecord, 16)
Me.txtActualWeight.Value = .Cells(currentRecord, 17)
Me.cboBarrelType.Text = .Cells(currentRecord, 18)

Exit For
End If
If IsEmpty(orderNumber) Then
MsgBox Prompt:=Me.txtOrderNumber.Value, Title:="Record Not Found"
Me.txtOrderNumber.Value = ""
Me.TextBox1.SetFocus
Exit For
End If
Next orderNumber
End With
End Sub

ProteanBeing
09-07-2010, 10:45 AM
setfocus does not work. I think it's because the end result of the afterUpdate event goes to the next tab of the object that called it.