Guus2005
AWF VIP
- Local time
- Today, 22:43
- Joined
- Jun 26, 2007
- Messages
- 2,642
CurrentDb should be equivalent to DBEngine.Workspaces(0).Databases(0) or DBEngine(0)(0) for short.
I always use CurrentDb because it is easier to type. In the code below Currentdb creates an error while DBEngine(0)(0) doesn't. Why is that?
When is one prefered above the other?
I use this code to get the fieldnames behind eachother with a : separator.
I always use CurrentDb because it is easier to type. In the code below Currentdb creates an error while DBEngine(0)(0) doesn't. Why is that?
When is one prefered above the other?
Code:
Public Sub EchoFieldnames()
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
' Set tdf = CurrentDb.TableDefs("tblCRB_IMPORT") 'Creates error:3420: Object invalid or no longer set.
Set tdf = DBEngine(0)(0).TableDefs("tblCRB_IMPORT")
For Each fld In tdf.Fields ‘<<<<where the error occures
Debug.Print fld.name & ":";
Next fld
Debug.Print
End Sub
Last edited: