Setting Bitwise Properties

Some properties store bitwise values. To compare bitwise values you use the bitwise comparison operators: And, Eqv, Not, Or, Xor, and Imp. A bitwise comparison is a bit-by-bit comparison of the individual bits of a value, rather than the value as a whole. To correctly store and retrieve values for these properties, you must use bitwise operators. For example, the Attributes property of a TableDef object defines certain characteristics such as how the table is linked. To check this property for a TableDef object, you may use the following line of code, where tdf represents the TableDef object.

If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
	' Perform some action on TableDef object.
	.
	.
	.
End If
	

If the result is a nonzero value, then the attribute dbAttachedTable is set for the table. If the result is zero, then that particular attribute isn’t set.

The previous example uses the And operator to retrieve bitwise values. You can use the Or operator to set bitwise values, and the And and the Not operators together to clear them.

Microsoft Access Users When you create an object through DAO by using Microsoft Jet, only the standard built-in properties are created in the new object’s Properties collection. However, when Microsoft Access creates a Microsoft Jet object, it may add several user-defined properties to objects. These properties are a special case of user-defined properties known as application-defined properties. For example, when you create a table in the Microsoft Access user interface, and type a value in the Description field, it automatically adds a new property to the TableDef object to represent the description.

Microsoft Access doesn’t automatically add these application-defined properties to new objects. For example, when you create a new table through the user interface in Microsoft Access, the Description and Format properties are not created unless you type a value in the Description and Format fields. This can cause a problem because when you try to read the value of these properties on a table where they have not been specified, a run-time error occurs. The technique for avoiding this problem, and for writing more robust property-retrieval code in general, is to trap for errors when looking at Property objects. For more information, see “Retrieving Properties” later in this chapter.

You can add properties not created by Microsoft Access through the user interface, by using the user interface, or by creating the property in code and appending it to the appropriate object’s Properties collection. For example, if you want to include a Description property in tables you create from code, you must add it to the Properties collection by using the CreateProperty method of the TableDef object.