Results 1 to 6 of 6
  1. #1
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29

    Query not working with criteria Like or Not Like

    I've a query which the user needs to select a button for the location (GDC or Others) in the interactive form :

    When GDC button is clicked,
    Private Sub GDC_Click()
    Me!location = "Like " & Chr(34) & "*GDC*" & Chr(34)


    DoCmd.OpenQuery "queryname"
    End Sub



    When Others button is clicked,
    Private Sub Others_Click()
    Me!location = "Not Like " & Chr(34) & "*GDC*" & Chr(34)
    DoCmd.OpenQuery "queryname"
    End Sub



    Query


    But the query not working. Please help.
    Click image for larger version. 

Name:	query not working.jpg 
Views:	17 
Size:	59.7 KB 
ID:	52021
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Not sure why you are using Chr(34)?

    Why not
    Code:
    Me!location = "Like *GDC*"
    as you are not using any sort of variable?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29
    I'd also used
    Me!location="Like *GDC*"
    But, query also not working

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    Try Me!location = "Like ""*GDC*"""

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I think you approaching this all wrong.
    Put the Like expression in your query directly and remove the need for the complex formatting?

    Something like

    Code:
    SELECT * FROM YOUR TABLE 
    WHERE MyField Like "'*" & Forms!YourForm!YourSearchField & "*'"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    You cannot use query parameters in a criteria in that way

    you can use the eval function something like

    expr1: eval([myfield] & forms!myform!myfield)
    and set the criteria =true

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

Similar Threads

  1. Query Criteria Not Working
    By dbc23 in forum Queries
    Replies: 4
    Last Post: 01-18-2019, 12:03 PM
  2. Query Criteria of <=x not working
    By dwheatley in forum Queries
    Replies: 3
    Last Post: 12-05-2017, 08:24 AM
  3. Query Criteria not working
    By SteveApa in forum Queries
    Replies: 6
    Last Post: 01-16-2015, 03:29 PM
  4. Criteria in query is not working
    By sshel55 in forum Queries
    Replies: 7
    Last Post: 10-17-2013, 04:50 PM
  5. query criteria not working
    By George in forum Access
    Replies: 3
    Last Post: 10-30-2012, 12:14 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