W
William Benson
I wrote two methods of looping through fields in a table. One doesn't
*always* work -- maybe it never works -- ... and I am trying to find out
why not. Can someone please explain the reason METHOD2 results in the
runtime error "Object invalid or no longer set."? Could it have to do with
having instances of Access 2003 running?
METHOD1 (good)
Sub CountRecords()
Dim ws, db, tdf, F
Set ws = DBEngine.Workspaces(0)
Set db = ws.Databases(0)
Set tdf = db.TableDefs("MyTable")
For Each F In tdf.Fields
Debug.Print F.Name
Next F
End Sub
METHOD2 (not working now, but I thought maybe it sometimes has worked)
Sub CountRecords1()
Dim tdf, F
Set tdf = CurrentDb.TableDefs("MyTable")
For Each F In tdf.Fields
Debug.Print F.Name
Next F
End Sub
*always* work -- maybe it never works -- ... and I am trying to find out
why not. Can someone please explain the reason METHOD2 results in the
runtime error "Object invalid or no longer set."? Could it have to do with
having instances of Access 2003 running?
METHOD1 (good)
Sub CountRecords()
Dim ws, db, tdf, F
Set ws = DBEngine.Workspaces(0)
Set db = ws.Databases(0)
Set tdf = db.TableDefs("MyTable")
For Each F In tdf.Fields
Debug.Print F.Name
Next F
End Sub
METHOD2 (not working now, but I thought maybe it sometimes has worked)
Sub CountRecords1()
Dim tdf, F
Set tdf = CurrentDb.TableDefs("MyTable")
For Each F In tdf.Fields
Debug.Print F.Name
Next F
End Sub