Results 1 to 2 of 2
  1. #1
    mda is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2016
    Posts
    1

    Question How do you escape quotes within a Union Query?


    I am using IIF(criteria, true, false) in a SQL query in Access. It works when I run it as its own query.
    I need to use this IIF function within a Union query - meaning, I need to have something like:
    UNION (SELECT IIF(FieldName = “Field Value”, “Value1”, “Value2”)
    However, whenever I start include quotes in a union query, the query no longer works. I have tried double and single quotes, I've tried escaping the quotes and I'm at a loss for what to do next.
    Any suggestions, or is this by design? I have resorted to putting the SQL queries into a VBA function and then calling the VBA function from within the union query, but that is getting messy.
    Thanks!

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    The syntax of the bit of code you provided is not valid, but I can't suggest an alternative because I can't see the context of what you are trying to do. Suggest you explain in more detail the issue you are trying to overcome. Provide some sample data and the required outcome.

    I can say that with a union query you cannot change a field name dynamically, to do this you would need to build and run the query via vba.

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

Similar Threads

  1. Using the escape key to exit forms
    By joecamel9166 in forum Forms
    Replies: 9
    Last Post: 06-01-2016, 07:27 AM
  2. Replies: 4
    Last Post: 12-05-2014, 11:15 AM
  3. Save Data so Escape key doesn't work
    By MintChipMadness in forum Forms
    Replies: 13
    Last Post: 08-16-2012, 01:24 PM
  4. Escape field entry
    By torpid in forum Programming
    Replies: 3
    Last Post: 06-05-2011, 08:30 PM
  5. Line Return escape character
    By Jerry8989 in forum Access
    Replies: 8
    Last Post: 10-02-2009, 09:53 AM

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