I am using VBA to insert a queryset into an existing ms access 365 table with an SQL statement.
Code to insert query (working):
CurrentDb.Execute "Insert Into Tablename Select temp.* From temp",dbFailOnError 'if table exists
CurrentDb.Execute "Select temp.* Into Tablename From temp",dbFailOnError 'if table does not exist
But now, I am also trying to add values to a column not in the query (a log number) into the table for the inserted queryset. So lets say insert '1' into a column called Evtlog in the table for these records.
What I was hoping to do to add the log number into the column Evtlog (gives syntax error):
CurrentDb.Execute "Insert Into Tablename Select temp.* From temp Set Evtlog=1",dbFailOnError
But I get an error on this statement, is there anyway to combine "Select" with "Set"?
Preferably, I would prefer to use Select as the query columns can change, but I am open to other solutions - for example, can a column be added to the queryset?
CodePudding user response:
Try this:
CurrentDb.Execute "Insert Into Tablename Select temp.*, 1 As EvtLog From temp",dbFailOnError 'if table exists
CurrentDb.Execute "Select temp.*, 1 As EvtLog Into Tablename From temp",dbFailOnError 'if table does not exist