Results 1 to 13 of 13
  1. #1
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6

    Searching

    I recently had help creating a search box using a combo. Essentially you type in your number, pick from one of the three drop down opitions to search and then click Find. The form then populates with that record. Two of the three drop downs search fine but my first option always returns an error. It is my primary key and I assume it is having an issue because its an auto-number. I need that field to stay an auto-number so is there a way to get around that and be able to search it?




    Thanks in advance!

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    so does it search on multiple combo boxes or just 1 at a time? Can you give a sample of your data and search options and what it is not doing for you.

  3. #3
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6
    I use the combo box to pick which field to search. The user types in the number they which to search, then picks from a drop down which field to search in, and then click find. Here is my code:

    Private Sub cmdFind_Click()
    If IsNull(Me.txtFind) Then
    Me.FilterOn = False
    Else
    Me.Filter = "[" & cboFld & "]='" & txtFind & "'"
    Me.FilterOn = True
    End If
    End Sub


    So the user can't search all three fields, they have to pick one. My records can have three unique identifiers and one is an auto generated number from Access (in case I don't have the other two identifiers.) and I need to be able to pull a record up by searching that auto number. The error I'm getting is: "Run-time error '3464': Data type mismatch in criteria expression". My two other plain text fields search just fine.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    The autonumber is not text but numeric. If they pick that option, you need Me.Filter = "[" & cboFld & "]=" & txtFind

    Are all 3 combo boxes visible on form?

  5. #5
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6
    I'm not sure what you mean..Sorry - I'm super new to access

    It is one combo box with a drop down with 3 options.

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Ok, so maybe:

    If IsNull(Me.txtFind) Then
    Me.FilterOn = False
    Else
    If Me.cboFld = 1 then 'for the autonumber field
    Me.Filter = "[" & cboFld & "]=" & txtFind
    Else
    Me.Filter = "[" & cboFld & "]='" & txtFind & "'"
    End If
    Me.FilterOn = True
    End If

    Again if I am understanding it right, if you are searching the autonumber field, that is a numeric type so has different syntax then searching a text field.

  7. #7
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6
    I still get the same error

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

  9. #9
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Give an example of the process using actual data. So you pull down the combobox list and select the first option which is the number 1? Then you have a text field called txtfind and in this you type in what value?

  10. #10
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6
    This is what the form looks like with the search box filled in


    Here is the error I'm getting when I search "SBARNumber"


    Here is what is supposed to happen (it works with the other two drop down items):




    "SBARNumber" is an auto generated number and on this form it shows up with "new" in the box. I have another form that is for new records and need that field to autopopulate that number. That info is then dropped into a table. The form in the pictures is used to search the info in the table in a form view so the user may make edits.

    I can try and send my database if that helps?

  11. #11
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    I think this should work. When searching the SBARNumber column, you have to search as numeric I believe.

    If IsNull(Me.txtFind) Then
    Me.FilterOn = False
    Else
    If Me.cboFld = "SBARNumber" then
    Me.Filter = "[" & cboFld & "]=" & txtFind
    Else
    Me.Filter = "[" & cboFld & "]='" & txtFind & "'"
    End If
    Me.FilterOn = True
    End If

  12. #12
    Cider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    6
    That worked!!! Thank you so much!

  13. #13
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Glad to help!!

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

Similar Threads

  1. Searching for Data
    By jimbo1283 in forum Forms
    Replies: 9
    Last Post: 04-25-2016, 10:15 AM
  2. Does searching have to be this way?
    By rojouz in forum Access
    Replies: 3
    Last Post: 01-21-2015, 11:50 AM
  3. Searching Question
    By Jbelle7435 in forum Programming
    Replies: 5
    Last Post: 05-15-2011, 07:48 AM
  4. Searching a Form
    By GraemeG in forum Programming
    Replies: 15
    Last Post: 04-10-2011, 11:05 AM
  5. Form Searching
    By Bike in forum Forms
    Replies: 2
    Last Post: 03-29-2011, 06:42 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