Why does this error (DAO)?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sub GetFlds(
Dim db As Databas
Set db = CurrentD

Dim td As TableDe
Dim fld As Fiel
Dim tblname As Strin

For Each td In db.TableDef
tblname = td.Nam
If Left(td.Name, 4) <> "MSys" The
Debug.Print tblnam
For Each fld In td.Fields <----Get Type Mismatch error her
Debug.Print fld.Nam
Nex
End I
Nex
End Sub
 
It's probably crossed references between DAO and ADO
The code below worked fine on my PC until I moved the ADO reference above
the DAO one.

Make sure that you have a reference to Microsoft DAO 3.6 Object Library.
Then either (or both)

Dim db As DAO.Database

or Make sure that the DAO Object Library comes before the ADO Object Library
in references.

Cheers,
Peter
 
Sub GetFlds()
Dim db As Database
Set db = CurrentDb

Dim td As TableDef
Dim fld As Field
Dim tblname As String

For Each td In db.TableDefs
tblname = td.Name
If Left(td.Name, 4) <> "MSys" Then
Debug.Print tblname
For Each fld In td.Fields <----Get Type Mismatch error here
Debug.Print fld.Name
Next
End If
Next
End Sub

Check Tools... References. This code uses the DAO object model;
Access2000 and later default to the ADO object model which (like DAO)
has Table and Field objects... but they are DIFFERENT objects!

Be sure that you have "Microsoft DAO x.xx Object Library" (latest
version) checked; if you won't be using ADO, uncheck the "Microsoft
ActiveX Data Objects" reference. And it would be prudent to

Dim db As DAO.Database
Dim td As DAO.Tabledef
Dim fld As DAO.Field
 
Back
Top