Results 1 to 5 of 5
  1. #1
    braff24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    7

    multiple field query Run-time error '13': Type mismatch

    Hi, I'm new to access and need some help with a project I'm working on. I have a database that will search through one field and I'm trying to change it so it will search through two fields and everything I try I get "Run-time error '13': Type mismatch".



    Here is what I have that works perfectly.

    Form_frmTools.RecordSource = "select * from Tools where " & "ToolName" & " LIKE '*" & txtSearchString & "*'"

    But I want to change it so it will search through the fields ToolName and PartNumber. This is what I have now and I'm getting the error.

    Form_frmTools.RecordSource = "select * from Tools where " & ("PartNumber" & " LIKE '*" & txtSearchString & "*'") Or ("ToolName" & " LIKE '*" & txtSearchString & "*'")

    I've also tried this with the same result.

    Form_frmTools.RecordSource = "SELECT Tools.PartNumber, Tools.ToolName, * FROM Tools WHERE (((Tools.PartNumber) Like "*" & [Forms]![frmSearch]! [txtSearchString] & "*")) OR (((Tools.ToolName) Like "*" & [Forms]![frmSearch]![txtSearchString] & "*"))"

    Any help is appreciated. Thanks in advance.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    I'm surprised you are getting that error since the code won't compile

    "select * from Tools where " & ("PartNumber" & " LIKE '*" & txtSearchString & "*'") Or ("ToolName" & " LIKE '*" & txtSearchString & "*'")

    also this does not seem right

    Form_frmTools.RecordSource

    I would expect to see

    Me.RecordSource if the code is being run in the same form

    or

    Me.subformcontrolname.Form.RecordSource if this is updating a subform


    or

    Forms!frmTools.RecordSource if the code is in a different form (and frmTools needs to be open)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Try:

    Form_frmTools.RecordSource = "select * from Tools where PartNumber LIKE '*" & Me.txtSearchString & "*' Or ToolName LIKE '*" & Me.txtSearchString & "*';"

    Form_frmTools. works just fine in VBA and it provokes intellisense popup tips. Forms! does not.

    I prefer to set form Filter and FilterOn properties instead of changing the RecordSource.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    braff24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    7
    Quote Originally Posted by June7 View Post
    Try:

    Form_frmTools.RecordSource = "select * from Tools where PartNumber LIKE '*" & Me.txtSearchString & "*' Or ToolName LIKE '*" & Me.txtSearchString & "*';"

    Form_frmTools. works just fine in VBA and it provokes intellisense popup tips. Forms! does not.

    I prefer to set form Filter and FilterOn properties instead of changing the RecordSource.
    Thanks! Works perfectly.

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Not trying to be smart here, but did you learn why? I'm curious.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. run-time error 13; type mismatch
    By osupratt in forum Programming
    Replies: 16
    Last Post: 10-11-2016, 02:40 PM
  2. Run-time error '13' Type mismatch
    By DCV0204 in forum Forms
    Replies: 4
    Last Post: 11-13-2013, 08:19 PM
  3. Run-time error 13 type Mismatch
    By Jaron in forum Programming
    Replies: 2
    Last Post: 09-13-2013, 02:33 PM
  4. Run-time error 13: type mismatch
    By ehe in forum Programming
    Replies: 3
    Last Post: 01-13-2013, 12:58 AM
  5. Run-time error '13': Type mismatch
    By uronmapu in forum Access
    Replies: 2
    Last Post: 07-10-2012, 07:59 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