[AccessD] Looping through TableDef.Fields

Christopher Hawkins clh at christopherhawkins.com
Mon Sep 6 19:16:52 CDT 2004


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]

The marked line causes an "Operation is not supported for this type
of object" error.

Why?

Respectfully,

Christopher Hawkins
Software Developer
(559) 687-7591
http://www.christopherhawkins.com





More information about the AccessD mailing list