Consulting

Results 1 to 3 of 3

Thread: FORM - goto first text box if not found

  1. #1
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location

    FORM - goto first text box if not found

    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.

    [vba]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[/vba]
    Last edited by Aussiebear; 09-07-2010 at 03:42 PM. Reason: Applied VBA tags to code
    "The amount of stupid people in the world is God's way of punishing the smart people" - protean_being

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    Is this what you mean?

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location
    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.
    "The amount of stupid people in the world is God's way of punishing the smart people" - protean_being

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •