Article ID: 178745
Article Last Modified on 1/22/2007
Option Explicit
'The following procedure accepts three arguments: prpName, prpType,
'and prpValue.
'
'prpName: a String value representing the name of the property
' you want to create.
'
'prpType: an Integer value representing the data type of the
' property you want to create. To view valid settings for
' this argument, search online help for "Type property,"
' display the topic "Type property (DAO)" and note the
' constants available for Property objects.
'
'prpValue: a Variant value representing the value of the property
' you want to create.
'
Sub CreateCustomProp(prpName As String, prpType As Integer, _
prpValue As Variant)
Dim db As Database
Dim doc As Document
Dim prp As Property
Set db = CurrentDb
Set doc = db.Containers!Databases.Documents!UserDefined
Set prp = doc.CreateProperty()
With prp
.Name = prpName
.Type = prpType
.Value = prpValue
End With
doc.Properties.Append prp
End Sub
CreateCustomProp "Language", dbText, "English"
Option Explicit
'The following procedure accepts one argument: prpName
'
'prpName: a String value representing the name of the property
' whose value you want to retrieve.
'
Function GetCustomProp(prpName As String) As Variant
Dim db As Database, prp As Property
Dim doc As Document
Set db = CurrentDb
Set doc = db.Containers!Databases.Documents!UserDefined
On Error Resume Next
Set prp = doc.Properties(prpName)
If Err.Number = 0 Then
GetCustomProp = prp.Value
Else
MsgBox "Property Not Found"
GetCustomProp = Null
End If
End Function
?GetCustomProp("Editor")
Note that "Nancy Davolio" is returned to the Debug window.
'The following procedure accepts three arguments: prpName, and
'prpValue.
'
'prpName: a String value representing the name of the property
' you want to create.
'
'prpValue: a Variant value representing the value of the property
' you want to set.
'
Sub SetCustomProp(prpName As String, prpValue)
Dim db As Database, doc As Document
Dim prp As Property
Set db = CurrentDb
Set doc = db.Containers!Databases.Documents!UserDefined
Set prp = doc.Properties(prpName)
prp.Value = prpValue
End Sub
SetCustomProp "Editor", "Andrew Fuller"
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: kbmacro vba
Keywords: kbhowto kbprogramming KB178745