[AccessD] Looping through TableDef.Fields

Gustav Brock gustav at cactus.dk
Tue Sep 7 05:04:35 CDT 2004


Hi Christopher

Also:

     Set td = db.TableDefs(sTableName)

and don't forget to Set your objects to Nothing when leaving.

/gustav


> I've done this a thousand time.  But right now, I'm full of codeine
> (broke a toe 30 minutes ago) and cannot think worth squat.
 
> Why will this code not work?  THe error-causing line is indicated by
a --->>

> [code]
> Public Sub GetTableInfo(sTableName As String)

> Dim db As DAO.Database
> Dim td As DAO.TableDef
> Dim sSQL As String
> Dim fld As DAO.Field

> On Error GoTo Err_GetTableInfo

>     Set db = CurrentDb()
    
>     Set td = CurrentDb.TableDefs(sTableName)
>     --->For Each fld In td
>         CurrentProject.Connection.Execute "INSERT INTO zTable
> (TableName, FieldName, Alias, SortOrder) VALUES ('" & sTableName &
> "', '" & fld.Name & "', '" & fld.Name & "', 0)"
>     Next fld
    
> Exit_GetTableInfo:
>     Exit Sub

> Err_GetTableInfo:
>     MsgBox Err.Description
>     Resume Exit_GetTableInfo
> End Sub
> [/code]




More information about the AccessD mailing list