Can I use a variable for a table name in a SQL statement using VBA



I'm trying to append data from one table to another using a SQL string in VBA
but the table names are always changing so I want to use variables for the
table names. Any ideas?

Daryl S

Ambushsinger -

Yes, you can do this. Set up variable to hold the SQL string (e.g. strSQL),
and build your code into the string. For example:

strSQL = "INSERT INTO [" & strIntoTableName & "] SELECT * FROM [" &
strFromTableName & "];"

Debug.Print strSQL

The Debug.Print statement will display the evaluated code in the immediate
window if you have the code pane open during testing. This will help you
catch missing delimeters or typos more easily.

If you have problems, post your code and the results from the immediate
window so we can help.

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