Results 1 to 5 of 5
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Variables In VBA

    I am attempting to compile the syntax below to dynamically create a query using DAO. However, I keep getting an error of (on the "1")
    Expected End Of Statement

    What do I need to alter in this syntax so that it will compile & execute properly?


    Code:
    Dim va1213 As String
    va1213 = "Bojava12"
    
    
    qdf.SQL = "SELECT [storeRef].[empID], [storeRef]." & va1213 & " FROM storeRef WHERE ((([storeRef]." & va1213 & ") >= "1")) ORDER BY [storeRef].[empID];"

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The issue is that literal double-quotes often get confused with your text qualifiers.
    If I want literal double-quotes, I often use Chr(34) to return them, i.e.
    Code:
    ... & ") >= " & Chr(34) & "1" & Chr(34) & "))...
    Also note that many times, SQL will accept single quotes, so you can try this to:
    Code:
    ... & ") >= '1'))..."

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by JoeM View Post
    The issue is that literal double-quotes often get confused with your text qualifiers.
    If I want literal double-quotes, I often use Chr(34) to return them, i.e.
    Code:
    ... & ") >= " & Chr(34) & "1" & Chr(34) & "))...
    Also note that many times, SQL will accept single quotes, so you can try this to:
    Code:
    ... & ") >= '1'))..."
    Hmm...I knew you could use the chr(34) in SSMS but did not realize you could do such in access. Thank you for this answer and insight!

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Another point is that if val123 is a numeric, you should not have the quotes around the 1 at all.

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

Similar Threads

  1. Variables In VBA
    By jo15765 in forum Programming
    Replies: 3
    Last Post: 11-01-2016, 08:26 AM
  2. Hyperlink Variables
    By CCW8 in forum Access
    Replies: 5
    Last Post: 07-08-2013, 06:20 PM
  3. VBA variables in SQL
    By compooper in forum Programming
    Replies: 3
    Last Post: 07-06-2011, 11:04 AM
  4. VBA in variables
    By smikkelsen in forum Access
    Replies: 3
    Last Post: 11-12-2010, 03:14 PM
  5. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 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