>
Dim dbsDefault As Database, qdfTest As QueryDef
Dim rstTest As Recordset, prpMoose As Property
Dim intField As Integer, intProp As Integer
Set dbsDefault = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
Set qdfTest = dbsDefault.QueryDefs(0)
Set prpMoose = qdfTest.CreateProperty("Moose",dbBoolean, True)
qdfTest.Properties.Append prpMoose
Set rstTest = qdfTest.OpenRecordset()
Debug.Print "Is qdfTest.Properties(""Moose"")inherited? "
Debug.Print qdfTest.Properties("Moose").Inherited
Debug.Print "Is rstTest.Properties(""Moose"")inherited? "
Debug.Print rstTest.Properties("Moose").Inherited
For intField = 0 To rstTest.Fields.Count - 1
Debug.Print rstTest.Fields(intField).Name
On Error Resume Next
For intProp = 0 To rstTest.Fields(intField).Properties.Count - 1
Debug.Print rstTest.Fields(intField).Properties(intProp).Name
Debug.Print rstTest.Fields(intField).Properties(intProp).Type
Debug.Print rstTest.Fields(intField).Properties(intProp).Value
Debug.Print _
rstTest.Fields(intField).Properties(intProp).Inherited
Next intProp
Next intField
dbsDefault.Close
Example (Microsoft Access)
The following example creates a Property object in the Properties collection of a TableDef object, and then creates a new QueryDef object based on the same table. The Property object automatically exists in the Properties collection of the new QueryDef object. Next, the procedure checks the Inherited property for the Property objects in the Properties collections of both the TableDef and the QueryDef objects.
In the following example, the Microsoft Access DatasheetFontItalic property is created and appended to the Properties collection of the TableDef object. The DatasheetFontItalic property is defined by Microsoft Access rather than by the Microsoft Jet database engine. However, the property applies to data access objects. Therefore, in order to set it from Visual Basic code, you must first create a Property object corresponding to that property and append it to the Properties collection of the data access object. It is necessary to create the property only the first time you set it.
Sub CheckInherited()
Dim dbs As Database, tdfOrders As TableDef, qdfOrders As QueryDef
Dim prpTableDef As Property, prpQueryDef As Property
Dim strSQL As String
' Return Database variable that points to current database.
Set dbs = CurrentDb
Set tdfOrders = dbs.TableDefs!Orders
' Create Property object and append to Properties collection.
Set prpTableDef = tdfOrders.CreateProperty("DatasheetFontItalic", _
dbBoolean, True)
tdfOrders.Properties.Append prpTableDef
Debug.Print prpTableDef.Inherited
' Create QueryDef based on Orders table.
strSQL = "SELECT * FROM Orders WHERE ShipCountry = 'USA'"
Set qdfOrders = dbs.CreateQueryDef("USAOrders", strSQL)
' Return Property object pointing to property.
Set prpQueryDef = qdfOrders.Properties!DatasheetFontItalic
Debug.Print prpQueryDef.Inherited
End Sub