Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Name for Append Query 1

Status
Not open for further replies.

TeddyTerrier

Programmer
Sep 25, 2003
4
US
I need to append some data to about 1500 different tables in Access. I would like to append the data to the different tables without having to specify the destination table for each table. I have a field in the original table (table that I am getting the appending data from) that has the different table names in it. What I did was this:

Transfer is the name of the table that the original data is coming from


1. Declared a public variable as a string: Public gTableName As String

2. Assigned a value to gTableName: gTableName = [tbridgeno] (tbridgeno is the field name in the original table)
(I checked in the watch window to see if the value of gTableName would change when scrolling through the table and it does)

3. Run a SQL: DoCmd.RunSQL “Insert Into [gTableName] (Date_of_Survey) Select Transfer.Inspdate From Transfer",-1


When I run this code I get an error message: “Table gTableName not found”
My variable gTableName is not being read as a variable but as if I was looking for the table “gTableName”

Do you know of a way to do this?

Thank you,

Primm Scott
 
Hi Teddy

Try this:

DoCmd.RunSQL "INSERT INTO " & gTableName & "(Date_of_Survey) Select Transfer.Inspdate From Transfer",-1

This should make Access read your variable name as a table name.

-Gary
 
Thank you very much Gary. I just tried your suggestion and it worked perfectly.

Primm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top