Results 1 to 7 of 7
  1. #1
    icaines9517 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jun 2016
    Posts
    7

    Help With Multi Field Search Form

    I need help creating a search form in which the user has the ability to search from approximately ten different fields within one large table containing over 1,000 records. I also want this search form to allow the user to leave some fields null. One of these fields is a combo box the others are text boxes, some being date fields. I tried doing this by creating a query and using a wildcard like statement for each field, however this does not work.

    I know the answer most likely includes code but I have no idea what and how to write the code to complete my task. I'm really just hoping someone can help me, I'm a novice user but I've already learned a lot and feel I can catch on if I know how to go about doing this. I have already searched the internet for a couple weeks and found different solutions but the ones I've tried so far has not worked for my needs. Any help would be appreciated.

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You must use vb to figure what fields to use, THEN build the 'where' clause.
    on the button click (find) event:
    Code:
    sub btnFind_click()
      If not isNull(txtName) then sWhere = "[name]='" & txtName & "'"
      if not isNull(cboState) then sWhere = sWhere & " and [state]='" & cboState & "'"
      'if not....
    
       If left(sWhere,4) = " and" then sWhere = mid(sWhere,5).  'Remove 1st and
    
    'Now apply where to the SQL or filter
      me.filter = sWhere
      Me.filterOn = true
    end sub

  3. #3
    icaines9517 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jun 2016
    Posts
    7
    Thank you for your response. Just a couple questions to ensure I'm able to execute this correctly. So I need to put this code on the on click event of my button correct? Also, if I want the results of the user input to essentially be a query can you show me how I would go about writing the code for that?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You can try the code available in this thread.
    Read the material and example and see if it applies.

  5. #5
    icaines9517 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jun 2016
    Posts
    7
    Thanks again, but one more thing.. When I tried your method for some reason it doesn't allow me to search for fields individually. (My code is below) For instance, if I search for a Status I have to put in a Position in order for it to work or else I get an error. Any idea on how to fix this?

    Private Sub Command3_Click()
    Dim sWhere As String


    If Not IsNull(Status) Then sWhere = sWhere & "([Status] = """ & Me.Status & """) AND "
    If Not IsNull(Position) Then sWhere = sWhere & " ([Position] = """ & Me.Position & """)"


    If Left(sWhere, 4) = " and" Then sWhere = Mid(sWhere, 5)
    Me.CandidatesResults.Form.Filter = sWhere
    Me.CandidatesResults.Form.FilterOn = True
    End Sub

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    icaines9517 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jun 2016
    Posts
    7
    Yeah I checked out the material and the example and it doesn't apply to my needs. Thanks for your help though

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multi-field search form
    By rebeldolphin69 in forum Forms
    Replies: 2
    Last Post: 06-15-2016, 05:28 AM
  2. Multi-Field Search Using a Combo Box
    By amkp711 in forum Programming
    Replies: 5
    Last Post: 03-03-2015, 10:07 AM
  3. Replies: 12
    Last Post: 08-17-2013, 11:49 PM
  4. Multi-field Search
    By bubba61 in forum Queries
    Replies: 20
    Last Post: 04-16-2013, 10:21 AM
  5. Multi Field Combo search Form
    By Andyjones in forum Access
    Replies: 3
    Last Post: 03-12-2012, 02:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums