Hello Stefan
There seems to be a syntax error on the db.Execute line, because it goes red
when I paste in the code. I tried removing the underscore and getting the
whole command on one line, but that made no difference. I have tried to see
what the syntax eror is, but can't!
Also, given that the table with the fields I want is called [all dates], and
the table into which I want to add the fieldnames is called [fields_from_all
dates], with field [fname], would I be right in amending the Set td line
to:
Set td = db.TableDefs([all dates])
and amending the db.Execute line to:
db.Execute "INSERT INTO [fields_from_all dates] ([fields_from_all dates],
[fname]) " & _
"VALUES ('" & [all dates] & "', '" & fd.Name "')"
(after also correcting the syntax error!)
Thanks again for this: I'm learning!
Les
Stefan Hoffmann said:
hi Leslie,
Leslie said:
Thanks for your suggestion.
You'll have to excuse my ignorance I'm afraid: how do I look at the
TableDefs("yourTable").Fields - or rather, how do I actually get the
field names into a new table?
For example:
Public Sub Foo(ATableName As String)
Dim db As DAO.Database
Dim fd As DAO.Field
Dim td As DAO.TableDef
Set db = CurrentDb
Set td = db.TableDefs(ATableName)
For Each fd in td.Fields
db.Execute "INSERT INTO [yourTable] ([tableName], [fieldName]) " & _
"VALUES ('" & ATableName & "', '" & fd.Name "')"
Next fd
Set td = Nothing
Set db = Nothing
End Sub
mfG
--> stefan <--