Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"INSERT INTO" vba code not working 1

Status
Not open for further replies.

accessjack

Programmer
Dec 2, 2004
28
US
To append new records from tblOne to tblTwo, I use an action append query to add records where the id field in tblOne does not exist in tblTwo. I am trying to do this using vba rather than an action query. Below is my code. The code compiles and executes but 0 records are appended (no error messages). I can't figure out why. tblTwo has no records in it so I would expect all records from tblOne to be appended to tblTwo. Can anyone figure out why this is not working?

sql01 = "INSERT INTO [tblTwo]([Id]) " & _
"SELECT [tblOne].[Id] " & _
"FROM [tblOne] " & _
"LEFT JOIN [tblTwo] " & _
"ON [tblOne].[Id] = [tblTwo].[Id] " & _
"WHERE [tblTwo].[Id] = " & "'" & Null & "'"

Thanks,
AccessJack
 
Replace this:
"WHERE [tblTwo].[Id] = " & "'" & Null & "'"
with this:
"WHERE [tblTwo].[Id] Is Null"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top