How Do I Create A Search Box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d4zza
    New Member
    • Mar 2010
    • 23

    #1

    How Do I Create A Search Box?

    Hi folks, looking for help on what I reckon should be easy, but can't seem to find an easy solution.

    I've tried searching loads of different solutions, but none seem to be for what I'm trying to do, a simple search box.

    Using Access 97, I've created a form - frmTests - which shows, in Form view as continous forms, all records from a table relating to items being tested.

    In previous databases, I would have just placed a command button with simply...

    Code:
    Private Sub cmdGoFindText_Click()
    
        Screen.PreviousControl.SetFocus
        DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
    
    End Sub
    But with this database, I'm wanting to something very similar, except the search string input box already exists on the form, call it, for example, txtSearchString to save the user from scrolling down thousands of records. I type in a string to the text box, then click a "Go" button next to it, which will then carry out a sort of "Find Next" style function and highlight the text I'm looking for.

    In my head, it seems a very simple task, which shouldn't have much code to it. I know I could just use the DoMenuItem feature instead, but it's not what the user wants.

    Currently, my code looks like this, and appears to do nothing, no failure, no highlight..

    Code:
    Private Sub cmdGoFindText_Click()
        If IsNull(Me.txtTextToFind) = True Then
            MsgBox ("No search term entered!")
            Me.txtTextToFind.SetFocus
        Else
            strWhere = Me.txtTextToFind
            DoCmd.FindRecord strWhere, acEntire, True, acSearchAll, True, acAll, True
        End If
    
    End Sub
  • munkee
    Contributor
    • Feb 2010
    • 374

    #2
    d4zza just to clarify you are wanting them to be able to find the first instance then click again to find the next instance etc? or just filter the records based on the string (which you seem to be able to do anyway)

    Comment

    • d4zza
      New Member
      • Mar 2010
      • 23

      #3
      Originally posted by munkee
      d4zza just to clarify you are wanting them to be able to find the first instance then click again to find the next instance etc? or just filter the records based on the string (which you seem to be able to do anyway)
      Hi, sorry for late reply, was trying various solutions.

      Just wanted a simple search once function, no filter. Unbound text box, txtTextToFind, on the form is used to enter a string of text to find, then user clicks a "Go" command button, and the form will find and highlight the first instance, no find next required.

      I did crack it this morning though. Based on the result with previous script, where nothing appeared to happen, I added in a field reference to focus on before searching. Code is now...

      Code:
      strWhere = Me.txtTextToFind
      Me.ReferenceNo.SetFocus
      DoCmd.FindRecord strWhere
      I'm only having to search the one field, ReferenceNo, and they all have unique entries.

      Comment

      Working...