Using the Attributes Property to Specify Additional Field Characteristics

In addition to standard field properties, you can use the Attributes property to specify additional characteristics for fields. For example, in Microsoft Access 97 table Design view, you create a Hyperlink field by setting the value in the Data Type column to Hyperlink. However, there is no DAO Type property setting for Field objects that corresponds to a Hyperlink field. This is because, at the Jet database engine level, a Hyperlink field is actually a Memo field that uses the dbHyperlinkField setting of the Attributes property to identify itself to Microsoft Access. While you can use DAO to create a Hyperlink field and work with its data, its hyperlink functionality is only available when the database is opened with Microsoft Access 97.

You can also use the Attributes property to create a field whose value is automatically incremented to a unique Long value for new records. Create a Field object of type Long, and set the Attributes property for the field to dbAutoIncrField. The resulting field is equivalent to a Microsoft Access AutoNumber field.

The following example creates a table named Hyperlinks that contains an automatically incrementing field and a hyperlink field, where strDbPath is the path to the database:

Dim dbs As Database, tdf As TableDef

Set dbs = OpenDatabase(strDbPath)
Set tdf = dbs.CreateTableDef("Hyperlinks")

' Create and append fields in one step.
With tdf
	.Fields.Append .CreateField("ID", dbLong)
	.Fields("ID").Attributes = dbAutoIncrField
	.Fields.Append .CreateField("Hyperlink", dbMemo)
	.Fields("Hyperlink").Attributes = dbHyperlinkField
End With
dbs.TableDefs.Append tdf

See Also For information about using other Attributes property settings with Field objects, search the DAO Help index for “Attributes property.”