PC Review


Reply
Thread Tools Rate Thread

DAO TableDef Not Working

 
 
=?Utf-8?B?TURX?=
Guest
Posts: n/a
 
      20th Jun 2005
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.
--
Hmm...they have the Internet on COMPUTERS now!
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      20th Jun 2005
"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)


 
Reply With Quote
 
=?Utf-8?B?TURX?=
Guest
Posts: n/a
 
      20th Jun 2005
AHA! I knew it some some silly detail I'd forgotten about. Works like a
charm. Thanks, DG.
--
Hmm...they have the Internet on COMPUTERS now!


"Dirk Goldgar" wrote:

> "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)
>
>
>

 
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
Re: DAO.TableDef - Connect Roger Carlson Microsoft Access External Data 0 21st Jul 2009 02:21 PM
Using TableDef Bill Microsoft Access Form Coding 6 6th Jan 2007 03:32 AM
TableDef =?Utf-8?B?RHdpZ2h0?= Microsoft Access Forms 3 4th May 2006 10:06 PM
TableDef Lee T. Microsoft Access 1 17th Mar 2004 04:17 AM
Set a tabledef = Nothing soncken Microsoft Access 0 15th Sep 2003 11:50 AM


Features
 

Advertising
 

Newsgroups
 


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