Dynamic Query Question

M

Melinda

I have 55 tables that I need to append to 1 master table. The 55 tables are
created by an outside program that picks random numbers (I can't change this
part of the process). I do not want to have to change the source table on my
append query 55 times. How can I use VBA to write a procedure to accomplish
this?

Thank You.
 
M

Marshall Barton

Melinda said:
I have 55 tables that I need to append to 1 master table. The 55 tables are
created by an outside program that picks random numbers (I can't change this
part of the process). I do not want to have to change the source table on my
append query 55 times. How can I use VBA to write a procedure to accomplish
this?


I don't see where you explained where the table names a re
coming from. I suggest a table and here's some code based
on that assumption:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("TableNames", dbOpenSnapshot)
Do Until rs.EOF
strSQL = "INSERT INTO MasterTable SELECT * FROM [" _
& rs!tablename & "]"
db.Execute strSQL, dbFailOnError
rs.MoveNext
Loop
rs.Close : Set rs=Nothing
Set db = Nothing
 

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