Syntax Error with SQL code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan7056
    New Member
    • Jun 2012
    • 1

    Syntax Error with SQL code

    I Am fairly new at using vba to edit a table in access. I am wanting to check to see if a table has a first and last name already in it and if it does not then I want to add them too the table.
    This is what I have so far...

    Code:
        SQLName = "INSERT INTO [" & OtherTable & "] " & _
        "SELECT [LastName] = " & Chr$(34) & LastName & Chr$(34) & _
        " AND [FirstName] = " & Chr$(34) & FirstName & Chr$(34) & _
        " WHERE NOT EXISTS (SELECT * " & _
        "WHERE code = " & Chr$(34) & LastName & Chr$(34) & " AND " & Chr$(34) & FirstName & Chr$(34)
        SQLName = "INSERT INTO [" & TableWithNames & "] " & _
        "SELECT [" & LastName & "], AND [" & FirstName & "] " & _
        "WHERE NOT EXISTS (SELECT * " & _
        "WHERE code = " & LastName & ", AND " & FirstName
    Thanks in advance for the help!
    Last edited by Rabbit; Jun 27 '12, 07:32 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    1) Your first string is overwritten by the second one.
    2) Your subquery has no FROM clause.
    3) You should get a hard-coded query working and then convert it to a dynamic query.

    Comment

    Working...