PC Review


Reply
Thread Tools Rate Thread

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

 
 
ambushsinger
Guest
Posts: n/a
 
      21st May 2010
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?
 
Reply With Quote
 
 
 
 
Daryl S
Guest
Posts: n/a
 
      21st May 2010
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.

--
Daryl S


"ambushsinger" wrote:

> 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?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use a variable for a table name in an SQL statement using VB ambushsinger Microsoft Access VBA Modules 2 25th May 2010 02:33 PM
Variable table/field name in statement Stu Microsoft Access VBA Modules 7 29th May 2008 03:58 PM
Using a SQL statement with variable parameters and variable criteria Froefel Microsoft ASP .NET 1 4th Jul 2007 10:38 AM
Macro Creating Variable and using variable in a SQL statement =?Utf-8?B?SmltbXk=?= Microsoft Excel Programming 4 25th Oct 2004 02:36 AM
Re: Pivot Table - Object variable or with block variable not set? George Nicholson Microsoft Excel Programming 1 16th Apr 2004 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 PM.