Results 1 to 2 of 2
  1. #1
    Newby is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Posts
    60

    Insert query with a variable

    I am try to run an insert query using double quotation marks around my varible, and receive "Expect end of statement" error message. Why does this seemingly easy task has to be so hard? Okay, what my wine for today.

    Private Sub cbx_BU_Change()

    Dim dBase As Database
    Dim stringSQL As String



    Set dBase = CurrentDb
    stringSQL = "SELECT BusUnit.BUnit INTO t_SelectedBU FROM BusUnit WHERE (((BusUnit.BUnit)=" & ""cbx.BU"" & "));"

    '"INSERT INTO t_SelectedBU ( BUnit) SELECT BusUnit.BUnit FROM BusUnit WHERE (((BusUnit.Parent)= " & cbx.BU & "));"
    dBase.Execute stringSQL, dbFailOnError
    MsgBox "Done"
    End Sub

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I like to use ther ASCII respresentation of double quotes (Chr(34)), i.e.

    Code:
    stringSQL = "SELECT BusUnit.BUnit INTO t_SelectedBU FROM BusUnit WHERE (((BusUnit.BUnit)=" & Chr(34) & cbx.BU & Chr(34) & "));"

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  4. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  5. Replies: 3
    Last Post: 02-16-2010, 10:43 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