"MDW" <(E-Mail Removed)> wrote in message
news:9D333D44-62B3-4780-BF4A-(E-Mail Removed)
> OK, I'm sure I've done this before, but I can't remember how. All I
> want to do is get the list of field names from a table. The table
> will always be called TEMP_IMPORT. Here's the code I have:
>
> Dim objT As DAO.TableDef
> Dim F As DAO.Field
> Dim strCols As String
>
> Set objT = CurrentDb.TableDefs("TEMP_IMPORT")
>
> For Each F In objT.Fields
>
> strCols = strCols & "," & F.Name
>
> Next
>
> Everytime I run it, I get an error message saying "Object is invalid
> or is no longer set." It highlights the code "objT.Fields".
>
> What am I doing wrong? I'm on Access2k, Windows2k. Thanks.
You need to get the TableDef object from a Database object that remains
in existence while you use the TableDef. For example:
Dim db As DAO.Database
Dim objT As DAO.TableDef
Dim F As DAO.Field
Dim strCols As String
Set db = CurrentDb
Set objT = db.TableDefs("TEMP_IMPORT")
For Each F In objT.Fields
strCols = strCols & "," & F.Name
Next
Set objT = Nothing
Set db = Nothing
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)