How to add a search field that will go directly to the record entered?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Yantis
    New Member
    • Aug 2010
    • 49

    #1

    How to add a search field that will go directly to the record entered?

    I have a form with ID, Name, Class and several Scores.
    I want to be able to enter the ID and that record comes up so that I can just use tab to enter the scores.
    Example: 1024 tab 3 tab 4 tab 3 tab 6 tab 9 tab tab
    by entering 1024 I would go to that record and be able to start entering the scores. the last tab would take me back to the ID field for the next record source.
    The plan is to never have to use the mouse (in the search at the bottom of the screen).
    I figure I will need VBA code OnUpdate or OnEnter to goto the record entered.
  • Steven Kogan
    Recognized Expert New Member
    • Jul 2010
    • 107

    #2
    The control wizard for a new combo box has an option to find a record based on what you select.

    Click the combo box control, then click on your form, and if you have the wizards enabled it will prompt you on what to do.

    A sample of the code generated is:
    Code:
    Private Sub Combo6_AfterUpdate()
        ' Find the record that matches the control.
        Dim rs As Object
    
        Set rs = Me.Recordset.Clone
        rs.FindFirst "[ID] = " & Str(Nz(Me![Combo6], 0))
        If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

    Comment

    • Daniel Yantis
      New Member
      • Aug 2010
      • 49

      #3
      That works great! I added the following so that it would auto advance and clear the search field for the next search:

      Code:
          Me![Score1].SetFocus
          Me![SearchID].Value = Null
      I'm so new that I haven't used the control wizard (didn't know about it).
      Last edited by NeoPa; Aug 5 '10, 10:59 PM. Reason: Please use the [CODE] tags provided

      Comment

      • Steven Kogan
        Recognized Expert New Member
        • Jul 2010
        • 107

        #4
        Are you setting the combo box value to null? Or your ID field value to null (which would erase your data)?

        I'm surprised your combo box name would be ID.

        Comment

        • Daniel Yantis
          New Member
          • Aug 2010
          • 49

          #5
          I edited the pasted info so it would be understandable.
          The combo box is [searchid]. I just fixed it in my last post.

          Comment

          • Steven Kogan
            Recognized Expert New Member
            • Jul 2010
            • 107

            #6
            To avoid going to a new record after the last tab, set the 'Cycle' property, on the 'Other' tab of your Form properties to 'Current Record'.

            Comment

            • Daniel Yantis
              New Member
              • Aug 2010
              • 49

              #7
              That's cool! So much to learn in too little time. Sorry to be such a schmuck. I have to finnish this project by Saturday for a contest.

              Comment

              Working...