You can create, change, delete user-defined properties in the
Properties collection of a
Database object (CurrentDb). These properties are persistent (i.e. they are stored in the .mdb or .accdb file).
To create a new property:
Code:
Function CreateDbProperty(PropertyName, PropertyValue)
'
' This function is called to create a new (user-defined) property
' of the Database object.
'
' It returnd True if successfull, an error code otherwise.
'
#If ERR_ON Then
On Error GoTo Err_CreateDbProperty
#End If
Dim prpNew As Property
Set prpNew = CurrentDb.CreateProperty(PropertyName, dbText, PropertyValue)
CurrentDb.Properties.Append prpNew
Set prpNew = Nothing
Exit_CreateDbProperty:
Exit Function
Err_CreateDbProperty:
CreateDbProperty = Err.Number
Resume Exit_CreateDbProperty
End Function
To retrieve the value of an existing property:
Code:
Function GetDBProperty(PropertyName, PropertyValue) As Long
' This function is called to get a (user-defined) property
' of the Database object.
'
' It returnd True if successfull, an error code otherwise.
'
#If ERR_ON Then
On Error GoTo Err_GetDBProperty
#End If
Dim Prop_Database As DAO.Database
Dim Prop_lngRetVal As Long
Set Prop_Database = CurrentDb
PropertyValue = Prop_Database.Properties(PropertyName)
Prop_lngRetVal = True
Exit_GetDBProperty:
GetDBProperty = Prop_lngRetVal
Exit Function
Err_GetDBProperty:
PropertyValue = Null
Prop_lngRetVal = Err.Number
Resume Exit_GetDBProperty
End Function
To change the value of an existing property:
Code:
Function SetDBProperty(PropName, PropValue) As Integer
'
' This function is called to change the value of a (user-defined) property
' of the Database object.
'
' It returnd True if successfull, an error code otherwise.
'
#If ERR_ON Then
On Error GoTo Err_SetDBProperty
#End If
Dim Property As Property
Dim Database As Database
Set Database = CurrentDb
Set Property = Database.Properties(PropName)
Property.Value = PropValue
Database.Properties.Refresh
SetDBProperty = True
Exit_SetDBProperty:
Exit Function
Err_SetDBProperty:
SetDBProperty = Err.Number
Resume Exit_SetDBProperty
End Function