Multiple UPDATEs in one Access SQL query
Asked Answered
F

2

6

I'm trying to make a query like so:

UPDATE table1 SET col1 = 'foo', col2 = 'bar';
UPDATE table2 SET hi = 'bye', bye = 'hi';

But when I go to save, Access errors with:

Characters found after end of SQL statement

After some searching, it would appear this is because Access can only do one query at a time.

How can I do this?

Fin answered 25/9, 2012 at 11:27 Comment(2)
Can you make a VB procedure executing the two statements?Reichstag
Yes, you can only create/execute one query at a time when using "Create > Query".Gamecock
L
5

Where are you working? You can run multiple queries in VBA or via macros. Some examples:

CurrentDB.Execute "UPDATE table1 SET col1 = 'foo', col2 = 'bar';", dbFailOnError
CurrentDB.Execute "UPDATE table2 SET hi = 'bye', bye = 'hi';", dbFailOnError

Saved query:

CurrentDb.Execute "Query5", dbFailOnError
Lyly answered 25/9, 2012 at 11:29 Comment(0)
C
-1

I found this sample:

MS ACCESS 2007: UPDATE QUERY THAT UPDATES VALUES IN ONE TABLE WITH VALUES FROM ANOTHER TABLE

uses the designer to create the query easily:

UPDATE Big INNER JOIN Bot ON Big.PART = Bot.PART
SET Bot.MFG = [Big].[MFG];
Custodial answered 16/6, 2015 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.