How to read Database Properties (1 Viewer)

ysrini

New member
Local time
Today, 06:51
Joined
Sep 15, 2010
Messages
3
Hi, in the MS Access 2007, under menu File -> Database Properties -> Custom tab, i added some custom properties (say 'Source')

How can i read these custom property values via Macro?
The following didn't work:
MsgBox (db.Properties("Source").Value)

It says "Property not found"

I am trying to create custom property for data source and out, so i use these to dynamically change when file path changes too

Thanks
-srinivas y.
 

KenHigg

Registered User
Local time
Today, 06:51
Joined
Jun 9, 2004
Messages
13,327
I would suggest you don't use a macro and instead use VBA. Or if you have to use a marco, call a vba routine that does the msgbox.
 

ysrini

New member
Local time
Today, 06:51
Joined
Sep 15, 2010
Messages
3
Thanks Ken, i was doing in a VBA, i didn't mean 'macro' literally

How to accomplish in VBA? It says property not found
 

KenHigg

Registered User
Local time
Today, 06:51
Joined
Jun 9, 2004
Messages
13,327
Not being familiar with the property in the example you posted I would suggest you tinker around in the immediate window looking at properties until you find the property and proper syntax - :)
 

boblarson

Smeghead
Local time
Today, 03:51
Joined
Jan 12, 2001
Messages
32,059
Here's some code which I use to Set Custom Properties and then to get the value back. Paste these into a STANDARD module and then save the module like basDbProps. Then if available you should be able to use

MsgBox GetCustomProperty("Source")

Code:
    Function GetCustomProperty(strPropertyName As String) As String
        Dim db As Database
        Set db = DBEngine(0)(0)
        GetCustomProperty = db.Properties(strPropertyName)
    End Function

    Function CreateCustomProperty(strPropertyName As String, strValue As String)
        Dim db As Database
        Dim P As Property
        Set db = DBEngine(0)(0)
        Set P = db.CreateProperty(strPropertyName, DB_TEXT, strValue)
        db.Properties.Append P
    End Function
 

ysrini

New member
Local time
Today, 06:51
Joined
Sep 15, 2010
Messages
3
Thanks Bob,
for a Custom Property that is already defined (and value set) in the Database Properties -> Custom tab, the following doesn't seem to work

Dim db As Database
Set db = DBEngine(0)(0)
GetCustomProperty = db.Properties("Source")

Can you try this and let me know if it works for you for same scenario?

Meanwhile, i found this help online that's working

Dim cnt As Container
Dim doc As Document

Set cnt = DBEngine(0)(0).Containers!Databases
Set doc = cnt.Documents!userDefined

doc.Properties.Refresh
MsgBox (doc.Properties!Source)

Thanks
-srinivas y.
 

MarkK

bit cruncher
Local time
Today, 03:51
Joined
Mar 17, 2004
Messages
8,180
From Access Developer Reference, Application.CurrentDB Method

Note
In previous versions of Microsoft Access, you may have used the syntax
Code:
DBEngine.Workspaces(0).Databases(0) 
or 
DBEngine(0)(0)
to return a pointer to the current database. In Microsoft Access 2000, you should use the CurrentDb method instead. The CurrentDb method creates another instance of the current database, while the
Code:
DBEngine(0)(0)
syntax refers to the open copy of the current database. The CurrentDb method enables you to create more than one variable of type Database that refers to the current database. Microsoft Access still supports the
Code:
DBEngine(0)(0)
syntax, but you should consider making this modification to your code in order to avoid possible conflicts in a multiuser database.

Just for reference ...

Code:
MsgBox CurrentDB.Properties(PropertyName), vbInformation
 

Users who are viewing this thread

Top Bottom