Results 1 to 3 of 3
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Applying Multiple Criteria in VBA SQL Statement


    I am attempting to write an SQL statement in VBA that contains multiple "WHERE" conditions. Specifically, I want to filter where the "Assigned Reviewer" column is equal to a textbox in another form, and the value in the "AssociateReviewConversion" column is 2. When I run this code, it correctly applies the filter to "Assigned Reviewer" but does not apply the filter to the "AssociateReviewConverstion" column.

    Code:
    Dim strSource As String
    strSource = "SELECT  ID, Received, Event, [PRRB Case Number], [Red Flag], [Assigned Reviewer], AssociateReviewComplete, IntakeComplete, AssociateReviewConversion  " & _
    "FROM AssociateWindowQ " & _
    "Where [Assigned Reviewer] Like '*" & Forms!Login!FirstName & "*' " _
    & "And AssociateReviewConversion = 2"
    Me.AssociateWindow.RowSource = strSource
    Interestingly, when I modify the statement to only apply the filter to the "AssociateReviewConversion" field, it works correctly (see below).
    Code:
    Dim strSource As String
    If [Forms]![Associate Review]![Complete] = -1 Then
    strSource = "SELECT  ID, Received, Event, [PRRB Case Number], [Red Flag], [Assigned Reviewer], AssociateReviewComplete, IntakeComplete, AssociateReviewConversion  " & _
    "FROM AssociateWindowQ " & _
    "Where AssociateReviewConversion = 2"
    Me.AssociateWindow.RowSource = strSource
    Else
    I just can't get the code to apply both criteria at the same time. Can someone tell me what I'm missing here?

  2. #2
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Please disregard. I figured it out. I had another If statement after this code that was replacing this if statement. I'm so embarrassed. Marking this as solved.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    I always put the space on the next line, so it is easy to spot, rather than have to scroll over to the far right. However I rarely use the continuation character.
    Learn to debug.print such variables before trying to use them as well.
    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

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

Similar Threads

  1. Replies: 13
    Last Post: 11-07-2023, 01:33 AM
  2. applying criteria to 2 fields in different tables
    By dawnnolan54 in forum Queries
    Replies: 6
    Last Post: 09-02-2015, 04:01 PM
  3. Replies: 4
    Last Post: 04-22-2013, 06:45 AM
  4. Apply Filter 2 criteria not applying
    By ahightower in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03:31 PM
  5. Replies: 2
    Last Post: 05-09-2011, 06:45 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