Results 1 to 5 of 5
  1. #1
    Simsnet is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3

    SQL Query

    Hi,



    I have created a few tables and am having problems with a search that i added to the form.

    In short, I wish to display only records that have an exact match. At the moment, I have the following:

    Dim strsearch As String
    Dim txtSearch As String
    strText = Me.txtKeyword.Value
    strsearch = "SELECT * FROM CLAIM WHERE ((ID LIKE ""*" & strText & "*""))"
    Me.RecordSource = strsearch

    If I enter '6' in the search box, the results will display all records that contain the number 6. What is the correct query to display just the record with id 6? (without 16, 26, 36, 60 etc..)

    Thank you in advance.

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    strsearch = "SELECT * FROM CLAIM WHERE ID ='" & strText & "'"

    This assumes that the field ID is actually text and not a number

  3. #3
    Simsnet is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3
    I think this is where I am going wrong, ID = number (autonumber)

    What do I need to change to get it to work?

    Thanks again for your help!

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    strsearch = "SELECT * FROM CLAIM WHERE ID =" & strText

  5. #5
    Simsnet is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3
    Thank you @ Ajax. Seems the first query worked just fine.

    strsearch = "SELECT * FROM CLAIM WHERE ((ID ='" & strText & "'))"

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

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