Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Set Focus on search box (XP)

    I have a search box in the Form Header section. When the user first opens the form, the focus has been on the PID (payroll ID) field in the Detail section. That's dangerous, because some of my users have a habit of "adding" a new record by just keying a new PID!! Of course, that screws up my records. I've fixed that problem by making most of the fields in the Detail section Enabled: No and Locked: Yes.

    But, what I'd really like is to have the form open with the focus on that "search" combo box in the Form Header. Can someone offer the VBA code to make this happen. Thank you!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Set Focus on search box (XP)

    Put the following code in the On Load event of the form:

    Private Sub Form_Load()
    Me.txtSearchBox.SetFocus
    End Sub

    where txtSearchBox is the name of the text box you want to have the focus. If the name contains spaces (not recommended), enclose it in square brackets:
    Me.[Search Box].SetFocus

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Set Focus on search box (XP)

    Super! Thank you, Hans!

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Focus on search box (XP)

    you might also want to set controls you don't want users accidentally moving into to not have a Tab Stop (Tab Stop --> NO) and also not have AutoTab set.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Set Focus on search box (XP)

    Now, there's something I haven't tried. Thanks!

Posting Permissions

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