Results 1 to 2 of 2
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Using A String Literal In Query String

    I am attempting to append a string literal to a query string and execute the query. My issue is that I can not discover how to properly encapsulate the string literal with quotes so when the string is executed it fails. This is my syntax - what is the correct way to encapsulate the string with quotes?



    Code:
    Dim inputText As String, strSQL As String
    
    
    inputText = "Hi" 
    
    
    strSQL = "Select red, blue, green, " & inputText & "from house"
    Debug.Print strSQL
    
    
    Select red, blue, green, hi from house

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Single quotes are needed around text data types.

    strSQL = "Select red, blue, green, '" & inputText & " from house'"

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

Similar Threads

  1. Replies: 6
    Last Post: 06-20-2016, 01:29 PM
  2. Replies: 6
    Last Post: 05-29-2015, 10:21 AM
  3. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  4. Using a query instead of a SQL string with DAO
    By GraeagleBill in forum Programming
    Replies: 19
    Last Post: 10-08-2012, 03:11 PM
  5. Replies: 5
    Last Post: 05-29-2012, 08:50 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