What Library do I need to reference?

C

Conan Kelly

Hello all,

What Libaray do I need to reference in order to use Database and
TableDef data types in VBA as shown in the example below?

Thanks for any help anyone can provide,

Conan Kelly



Sub TableDefX()

Dim dbsNorthwind As Database
Dim tdfNew As TableDef
Dim tdfLoop As TableDef
Dim prpLoop As Property

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Create new TableDef object, append Field objects
' to its Fields collection, and append TableDef
' object to the TableDefs collection of the
' Database object.
Set tdfNew = dbsNorthwind.CreateTableDef("NewTableDef")
tdfNew.Fields.Append tdfNew.CreateField("Date", dbDate)
dbsNorthwind.TableDefs.Append tdfNew

With dbsNorthwind
Debug.Print .TableDefs.Count & _
" TableDefs in " & .Name

' Enumerate TableDefs collection.
For Each tdfLoop In .TableDefs
Debug.Print " " & tdfLoop.Name
Next tdfLoop

With tdfNew
Debug.Print "Properties of " & .Name

' Enumerate Properties collection of new
' TableDef object, only printing properties
' with non-empty values.
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " - " & _
IIf(prpLoop = "", "[empty]", prpLoop)
Next prpLoop

End With

' Delete new TableDef since this is a
' demonstration.
.TableDefs.Delete tdfNew.Name
.Close
End With

End Sub
 
A

Allen Browne

These objects are supplied by the DAO library.

If you are using Access 2000 or later, the library is called:
Microsoft DAO 3.6 Library

In Access 97, it should be:
Microsoft DAO 3.51 Library.

More info on the refrences for the different versions of Access here:
Solving Problems with Library References
at:
http://allenbrowne.com/ser-38.html

If you are just starting out with DAO, here's a summary:
The DAO Object Model
at:
http://allenbrowne.com/ser-04.html
 
D

Douglas J. Steele

In addition to the (absolutely correct) answers Alex and Allen gave you, be
aware that if you have references to both ADO and DAO, you'll find that
you'll need to "disambiguate" certain declarations, because objects with the
same names exist in the 2 models. For example, to ensure that you get a DAO
property, you'll need to use Dim prpLoop as DAO.Property (to guarantee an
ADO property, you'd use Dim prpLoop As ADODB.Property)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top