Access/VBA Library

ChangeProperty

Changes a property of the current database. If not it does not exist, then it will be added.

Syntax

ChangeProperty( propertyName, propertyType, propertyValue )
Parameters
Name Type Description
propertyName String Required. Name of the property to be changed.
propertyType Variant Required. Type of the property to be changed. Should be one of the field type constants like dbInteger, dbText, dbDate....
propertyValue Variant Required. Value of the property. The type of the value should correspondend with the specified propertyType.
Return value

Boolean : True when the property has been changed or created, otherwise False.

Code
Function ChangeProperty(propertyName As String, propertyType As Variant, propertyValue As Variant) As Boolean
    Const cErrPropertyNotFound = 3270

    Dim dbs As Database
    Dim prp As Property
    
    Set dbs = CurrentDb
    
    On Error GoTo ChangeProperty_Error
    dbs.Properties(propertyName) = propertyValue
    ' Property exist and is replaced
    ChangeProperty = True
    
ChangeProperty_Exit:
    Exit Function
    
ChangeProperty_Error:
    If Err = cErrPropertyNotFound Then
        ' If the property does not exist then create it
        Set prp = dbs.CreateProperty(propertyName, propertyType, propertyValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ShowError propertyName & " : " & Err.Description, "ChangeProperty"
        ChangeProperty = False
        Resume ChangeProperty_Exit
    End If
End Function

Remarks

  • When an error occured, an errormessage will pop up.