S
SenFan
Hi everyone. I am struggling with this code and could use some help from an
expert.
To start, I will explain my goal. I have a database that has a number of
tables that have all the same fields. Some of these tables will be deleted
and new tables will be added (with the exact same fields). I am trying to
create a query that will run through all of the tables in the Tabledefs
(other than the system tables) and copy the records to one table, whose name
(datatemp) will be constant. I really need the flexibility to have this
query run through any table added to the database.
Another feature I would like to add is that I would also like to update a
field with the Table's name before sending the data into the constant table.
Hope this makes sense.
Here is my code so far...
Dim dbs As DAO.Database
Dim tbl As DAO.TableDefs
Dim t As DAO.TableDef
Dim x As String
Dim sqlstr As String
Set dbs = CurrentDb
For Each t In dbs.TableDefs
If t.Attributes = 0 Then
MsgBox t.Name ' I placed this here to see if it works - It does
x = t.Name
MsgBox x ' I placed this here to see if it works, - It does
DoCmd.RunSQL "INSERT INTO Datatemp SELECT * FROM" & " " & x & ";"
'This doesn't work - It does not recognize the value of x
'How do I update a field called "Categery" with the table.name
value
'How do I send that value to my constant table Datatemp??
End If
Next t
If anyone could help I would be grateful. Thanks.
expert.
To start, I will explain my goal. I have a database that has a number of
tables that have all the same fields. Some of these tables will be deleted
and new tables will be added (with the exact same fields). I am trying to
create a query that will run through all of the tables in the Tabledefs
(other than the system tables) and copy the records to one table, whose name
(datatemp) will be constant. I really need the flexibility to have this
query run through any table added to the database.
Another feature I would like to add is that I would also like to update a
field with the Table's name before sending the data into the constant table.
Hope this makes sense.
Here is my code so far...
Dim dbs As DAO.Database
Dim tbl As DAO.TableDefs
Dim t As DAO.TableDef
Dim x As String
Dim sqlstr As String
Set dbs = CurrentDb
For Each t In dbs.TableDefs
If t.Attributes = 0 Then
MsgBox t.Name ' I placed this here to see if it works - It does
x = t.Name
MsgBox x ' I placed this here to see if it works, - It does
DoCmd.RunSQL "INSERT INTO Datatemp SELECT * FROM" & " " & x & ";"
'This doesn't work - It does not recognize the value of x
'How do I update a field called "Categery" with the table.name
value
'How do I send that value to my constant table Datatemp??
End If
Next t
If anyone could help I would be grateful. Thanks.