Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Create Custom Properties 1

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
I need to create a custom property

Is there a function or group of functions that can create, get and set custom properties? I'm Your Huckleberry!
 
Code:
Function GetOrSetProperty(ByVal strPropName As String, _
                    Optional ByVal strVal As String, _
                    Optional ByVal blnDebug As Boolean) As String
On Error GoTo ErrHandler

  Dim dbs As DAO.Database
  Dim cnt As DAO.Container
  Dim doc As DAO.Document
  Dim prp As DAO.Property

  ' Property not found error.
  Const conPropertyNotFound = 3270

  Set dbs = CurrentDb
  Set cnt = dbs.Containers!Databases
  Set doc = cnt.Documents!UserDefined
  
  doc.Properties.Refresh
  
  If Len(strVal) > 0 Then
    doc.Properties(strPropName) = strVal
  End If
    
  GetOrSetProperty = doc.Properties(strPropName)

  If blnDebug Then
    For Each prp In doc.Properties
      Debug.Print prp.Name, prp.Value
    Next prp
  End If

ExitHere:
    Exit Function
ErrHandler:
  If Err = conPropertyNotFound Then
    If Len(strVal) > 0 Then
      Set prp = doc.CreateProperty(strPropName, DAO.dbText, strVal)
      ' Append to collection.
      doc.Properties.Append prp
      Resume
    Else
      Resume Next
    End If
  Else
    ' Unknown error.
    MsgBox "Error in GetOrSetProperty() -" & Err & ":" & Err.Description
    Resume ExitHere
  End If
End Function
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
OK, I looked it over, and tried compiling the module but, as I expected got the error "user defined type not found" for dbs As DAO.Database

So, what reference am I missing?

David I'm Your Huckleberry!
 
I have the following references.

Visual Basic for Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft XML version 2.0
Microsoft XML v2.6

What else do I need to add? I'm Your Huckleberry!
 
Ok, that did the trick, now for the meat and potatoes.

Now, how to test it.

How can delete a custom property, once it is already set?

David I'm Your Huckleberry!
 
Code:
doc.Properties.Delete strPropName
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top