Append tables with all fields using VBA and Wildcards

J

Jorist

Does anyone have a VBA script that they would be willing to share that
appends all fields from Table A into Table B without using Access Append
Queries? These tables will always have the same fields and structures.

I am trying to get this accomplished with wildcards and without having to
hard code every field into the script as I have MANY tables to update.

Any help would be greatly appreciated.
 
M

Marshall Barton

Jorist said:
Does anyone have a VBA script that they would be willing to share that
appends all fields from Table A into Table B without using Access Append
Queries? These tables will always have the same fields and structures.

I am trying to get this accomplished with wildcards and without having to
hard code every field into the script as I have MANY tables to update.


An Append (INSERT INTO) query is the best way. The trick is
to construct the query properly before executing it.

If you have a table (or array) with the names of the tables
you want to archive, then you can use code along these
lines:

Set rs = db.OpenRecordset("tableoftables",dbOpenSnapshot)
Do Until .EOF
strSQL = "INSERT INTO " & rs!TableName & "* " _
& "SELECT " & rs!TableName & "* " _
& "FROM & rs!TableName"
db.Execute strSQL, dbFailOnError
rs.MoveNext
Loop
 
J

Jorist

Thanks Marsh, this helped.



Marshall Barton said:
An Append (INSERT INTO) query is the best way. The trick is
to construct the query properly before executing it.

If you have a table (or array) with the names of the tables
you want to archive, then you can use code along these
lines:

Set rs = db.OpenRecordset("tableoftables",dbOpenSnapshot)
Do Until .EOF
strSQL = "INSERT INTO " & rs!TableName & "* " _
& "SELECT " & rs!TableName & "* " _
& "FROM & rs!TableName"
db.Execute strSQL, dbFailOnError
rs.MoveNext
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top