Results 1 to 5 of 5
  1. #1
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17

    Need a query in VBA with AND's and OR's mixed together.

    Good day,



    I'm trying to write and sql string that essentially needs to work like this: WHERE a>b AND ((c AND d) or (e AND f))

    Of course, Access 2010 doesn't like brackets in that sort of thing and I am not very experienced with SQL.

    Can anyone help explain what I need to do for this? It would be greatly appreciated.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    WHERE a>b AND ((c AND d) or (e AND f))
    Not sure I understand the requirement.
    Are the variables numeric?
    Do you mean that either b+c+d or b+e+f are greater than a
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17
    Sorry, I was trying to keep it simple. a,b,c,d,e and f are all different statements.

    The actual line so far is : Where ShiftStart > " & todayvar & "AND Isnull(FlightSConf) AND FlightStart < " & dateVar & " OR IsNull(FlightEConf) AND FlightEnd < " & dateVar

    Only I need to be able to group them like above.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Use parentheses to manage the hierarchy of operations.

    Maybe you want:

    " WHERE ShiftStart > #" & todayvar & "# AND IsNull(FlightSConf) AND (FlightStart < #" & dateVar & "# OR FlightEnd < #" & dateVar & "#)"

    Note the # for delimiting date parameters.
    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.

  5. #5
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17
    Thanks everyone for the help. Turns out if you put the brackets on the inside of the "", you don't get that Expected: whatever Error!

    Final working answer: ShiftStart > " & todayvar & " And ((Isnull(FlightSConf) and FlightStart < " & dateVar & ") or (IsNull(FlightEConf) and FlightEnd < " & dateVar & "))"

    Have a nice day! Thanks again!

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

Similar Threads

  1. Expression with mixed value result
    By chelseasikoebs in forum Access
    Replies: 2
    Last Post: 10-23-2013, 09:18 AM
  2. Replies: 5
    Last Post: 12-15-2011, 11:16 AM
  3. Data mixed up
    By neo651 in forum Access
    Replies: 3
    Last Post: 09-28-2011, 04:05 PM
  4. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 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