How to get and set Custom Database properties in ADP?

B

Bill

Most of my MDB upsized ok but I cannot figure out how to read some custom
database properties that I use.

Example

'read version from Database, Properties, Custom
Set dblocal = CurrentDb()
myDBVersion = GetDatabaseProp(dblocal, "Version")

using:

Function GetDatabaseProp(dbDatabase, strPropertyName As String) As Variant
GetDatabaseProp =
dbDatabase.Containers!Databases.Documents("UserDefined").Properties(strPropertyName).Value
End Function


This is proabably because there is no DAO jet DB any more!

So how do I do I point to the equivalent Custom Properties in the ADP?

Thanks

Bill
 
S

Sylvain Lafontaine

For ADP:

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

' Properties are string values.
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:

''''' Call LogError(Err.Number, Err.Description, cModuleName &
cProcedureName)
Resume Exit_Sub

End Sub

' GetProperty(): returns TRUE if the property was already known; FALSE
otherwise.
' The value itself is passed by argument.

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
''''' Call LogError(Err.Number, Err.Description, cModuleName &
cProcedureName)
Resume Exit_Function

End Function
 
B

Bill

Thanks,

I looked at this and it still does seem quite right.

Sure this code does add properties that I can then read back with

For Each prop In CurrentProject.Properties
Debug.Print prop.Name
Next prop


But they do not appear in the Custom tab of Database Properties dialog

So where are those Custom Properties?


Thanks

Bill
 
S

Sylvain Lafontaine

Oups, sorry, I misread your question.

I'm sorry but these properties are not available from an Access ADP project.
This is also documented in the Help File: search for "database properties"
and you find the following note: « The Database properties of a Microsoft
Access project (.adp) are not available using Visual Basic. »
 
B

Bill

Hmmm.
Sounds like a bug to me.

Anyway, the approach you suggested will work, and if I use a form then I
will be able change them without resorting to code.

Thanks

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top