[AccessD] Looping through TableDef.Fields

John W. Colby jwcolby at colbyconsulting.com
Mon Sep 6 20:28:13 CDT 2004


For Each fld In td.Fields

John W. Colby
www.ColbyConsulting.com 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Christopher
Hawkins
Sent: Monday, September 06, 2004 8:17 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] Looping through TableDef.Fields


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


-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list