Accessing custom properties for an adp file

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I want to be able to define and manipulate custom office properties
for an ADP file from VBA code within the ADP. Now, I can
interactively right click on the file, choose properties, choose
custom, and create a custom property and value. The property and
value even persist into the ade file I make from the adp. So far, so
good.

The problem is I can't come up with any way to set or even read these
custom properties from vba inside the adp file. I've seen some
examples of doing it with word 2003, but nothing for Access...let
alone Access adp files. I've got to believe that since I can set and
retreive the data from the UI, there's got to be an api somewhere I
can call...but short of exporting the dll functions from MSAccess.EXE
and trying to guess, I can't seem to find a way. Anyone?

Alternatively, is there any way to associate metadata with an adp file
that can be read and written from within vba? The metadata must
persist across executions, not be loaded from an external
source...otherwise i could sneak it into the tag property of a startup
form or something. Any out of the box ideas welcome...or if there's
something blindingly obvious that I'm missing.
 
To my knowledge, you can't read/write the custom office properties from VBA
withing an ADP project. (But you can with a MDB file; see the fourth
message in the thread
http://groups.google.ca/group/micro...44a0d6846ac/91720a37202fca67#91720a37202fca67 .

This is one of these numerous things that have been left hanging up by MS
for ADP. However, you can have metadata properties that can be read/write
from VBA within ADP and that will persist from execution to execution:

Private Const cerrPropertyNotFound As Integer = 2455 ' For ADP, not MDB.

Public Sub Debug_DisplayProperties()

Dim db As CurrentProject
Set db = Application.CurrentProject

Dim i
For i = 0 To db.Properties.Count - 1
Debug.Print db.Properties(i).name & ": " & db.Properties(i)
Next

End Sub


Public Sub SetProperty(ByVal strPropName As String, _
ByVal varPropType_Bidon As Integer, _
ByVal varPropValue As Variant)

Const cProcedureName As String = "SetProperty"
On Error GoTo Err_Handler

Dim db As CurrentProject
Set db = Application.CurrentProject

If (IsNull(varPropValue)) Then varPropValue = ""

Dim i
For i = 0 To db.Properties.Count - 1
If (db.Properties(i).name = strPropName) Then
db.Properties(strPropName).Value = varPropValue
GoTo Exit_Sub
End If
Next

db.Properties.Add strPropName, varPropValue

Exit_Sub:
On Error GoTo 0
Set db = Nothing
Exit Sub

Err_Handler:
' Err_Handler: utilisée dans l'ancienne version.

Select Case err
Case cerrPropertyNotFound
db.Properties.Add strPropName, varPropValue

Case Else
' Call LogError(Err.Number, Err.Description, cModuleName &
cProcedureName)
End Select

Resume Exit_Sub

End Sub


' GetProperty() : return True if the property exists in the collection.

Public Function GetProperty(ByVal strPropName As String, _
ByRef strPropValue As Variant) As Boolean

Const cProcedureName As String = "GetProperty"
On Error GoTo Err_Handler

Dim db As CurrentProject
Set db = Application.CurrentProject

Dim i
For i = 0 To db.Properties.Count - 1
If (db.Properties(i).name = strPropName) Then
strPropValue = db.Properties(strPropName)
GetProperty = True
GoTo Exit_Function
End If
Next

GetProperty = False

Exit_Function:
On Error GoTo 0
Set db = Nothing
Exit Function

Err_Handler:
GetProperty = False

Select Case err
Case cerrPropertyNotFound
Case Else
' Call LogError(Err.Number, Err.Description, cModuleName &
cProcedureName)
End Select

Resume Exit_Function

End Function
 
Joe

Create with:-

CurrentProject.Properties.Add "PropertyName", "PropertyValue"

Read with:-

Dim P As AccessObjectProperty
AccessPropExists = False
For Each P In CurrentProject.Properties
If P.name = PropertyName Then
AccessPropExists = True
End If
Next P

HTH

Steve
 
Back
Top