By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

Syntax Error with SQL code

P: 1
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...

Expand|Select|Wrap|Line Numbers
  1.     SQLName = "INSERT INTO [" & OtherTable & "] " & _
  2.     "SELECT [LastName] = " & Chr$(34) & LastName & Chr$(34) & _
  3.     " AND [FirstName] = " & Chr$(34) & FirstName & Chr$(34) & _
  4.     " WHERE NOT EXISTS (SELECT * " & _
  5.     "WHERE code = " & Chr$(34) & LastName & Chr$(34) & " AND " & Chr$(34) & FirstName & Chr$(34)
  6.     SQLName = "INSERT INTO [" & TableWithNames & "] " & _
  7.     "SELECT [" & LastName & "], AND [" & FirstName & "] " & _
  8.     "WHERE NOT EXISTS (SELECT * " & _
  9.     "WHERE code = " & LastName & ", AND " & FirstName
Thanks in advance for the help!
Jun 27 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,357
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.
Jun 27 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.