Applies To Property object.
Description
Returns a value that indicates whether a Property object is inherited from an underlying object.
Return Values The return value is a Boolean data type that is True if the Property object is inherited. For built-in Property objects that represent predefined properties, the only possible return value is False. This property is always False in an ODBCDirect workspace. Remarks You can use the Inherited property to determine whether a user-defined Property was created for the object it applies to, or whether the Property was inherited from another object. For example, suppose you create a new Property for a QueryDef object and then open a Recordset object from the QueryDef object. This new Property will be part of the Recordset object's Properties collection, and its Inherited property will be set to True because the property was created for the QueryDef object, not the Recordset object.See Also CreateProperty method.
Specifics (Microsoft Access) Microsoft Access defines a number of properties that apply to Data Access Objects. Because these properties are defined by Microsoft Access, the Microsoft Jet database engine doesn't recognize them automatically. To set one of these properties by using Visual Basic, you must first create the property by using the CreateProperty method and then append it to the Properties collection of the object. For more information, see the Property object. When you create an object based on another object, the derived object inherits the properties of the original object. You can use the Inherited property to determine whether one of these properties was created for the object it is applied to, or if the property was inherited from another object. For example, suppose you want to set the Microsoft Access DatasheetFontName property for a TableDef object. If you are setting this property for the first time, you will need to create a corresponding Property object and append it to the Properties collection of the TableDef object. The Inherited property of the new Property object returns False (0). If you then create a new QueryDef object based on the table corresponding to the TableDef object, the DatasheetFontName property will be included in the Properties collection of the QueryDef object. The Inherited property of a Property object corresponding to this property returns True (–1). Example This example use the Inherited property to determine if a user-defined Property object was created for a Recordset object or for some underlying object.Sub InheritedX()
Dim dbsNorthwind As Database
Dim tdfTest As TableDef
Dim rstTest As Recordset
Dim prpNew As Property
Dim prpLoop As Property
' Create a new property for a saved TableDef object, then
' open a recordset from that TableDef object.
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set tdfTest = dbsNorthwind.TableDefs(0)
Set prpNew = tdfTest.CreateProperty("NewProperty", _
dbBoolean, True)
tdfTest.Properties.Append prpNew
Set rstTest = tdfTest.OpenRecordset(dbOpenForwardOnly)
' Show Name and Inherited property of the new Property
' object in the TableDef.
Debug.Print "NewProperty of " & tdfTest.Name & _
" TableDef:"
Debug.Print " Inherited = " & _
tdfTest.Properties("NewProperty").Inherited
' Show Name and Inherited property of the new Property
' object in the Recordset.
Debug.Print "NewProperty of " & rstTest.Name & _
" Recordset:"
Debug.Print " Inherited = " & _
rstTest.Properties("NewProperty").Inherited
' Delete new TableDef because this is a demonstration.
tdfTest.Properties.Delete prpNew.Name
dbsNorthwind.Close
End Sub
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 this 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 DAO 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 DAO object. It's necessary to create the property only the first time you set it.
Sub CheckInherited()
Dim dbs As Database, tdf As TableDef, qdf As QueryDef
Dim strSQL As String
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Orders table.
Set tdf = dbs.TableDefs!Orders
' Call SetAccessProperty function.
If SetAccessProperty(tdf, "DatasheetFontItalic", _
dbBoolean, True) = True Then
' Create QueryDef object based on Orders table.
strSQL = "SELECT * FROM Orders WHERE ShipCountry = 'USA';"
Set qdf = dbs.CreateQueryDef("USAOrders", strSQL)
' Return Property object pointing to property.
Debug.Print "Value of Inherited, TableDef object:", _
tdf.Properties!DatasheetFontItalic.Inherited
Debug.Print "Value of inherited, QueryDef object:", _
qdf.Properties!DatasheetFontItalic.Inherited
ExitCheckInherited
Else
MsgBox "Property not set successfully."
ExitCheckInherited
End If
ExitCheckInherited:
Set dbs = Nothing
Exit Sub
End Sub
This procedure calls the following function, which sets the property, creating it in the Properties collection if necessary:
Function SetAccessProperty(obj As Object, strName As String, _
intType As Integer, varSetting As Variant) As Boolean
Dim prp As Property
Const conPropNotFound As Integer = 3270
On Error GoTo ErrorSetAccessProperty
' Explicitly refer to Properties collection.
obj.Properties(strName) = varSetting
obj.Properties.Refresh
SetAccessProperty = True
ExitSetAccessProperty:
Exit Function
ErrorSetAccessProperty:
If Err = conPropNotFound Then
' Create property, denote type, and set initial value.
Set prp = obj.CreateProperty(strName, intType, varSetting)
' Append Property object to Properties collection.
obj.Properties.Append prp
obj.Properties.Refresh
SetAccessProperty = True
Resume ExitSetAccessProperty
Else
MsgBox Err & ": " & vbCrLf & Err.Description
SetAccessProperty = False
Resume ExitSetAccessProperty
End If
End Function