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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i get at database properties within an access project

Status
Not open for further replies.

Webermmn

IS-IT--Management
Jun 1, 2001
5
FR
Hi
I'm relatively new to VBA programming and something got me stumped right at the beginning.

I want to display some user-defined properties from the database properties (the ones you get from the 'file / database properties' menu) on a form. I have 2 problems with this:
- First i'm not sure where in the object module they are hidden and how to get to them.
- secondly i can't use the 'currentdb' object (i have set a reference to the DAO library).

The code snippet below turns up the 'Object variable or with block variable not set' error.

Dim dbs as database
set dbs = currentdb
debug.print dbs.name

With the debugger, the dbs variable still shows a contents of 'nothing'.

I suppose i've missed a basic step somewhere.

Can somebody help please!!
 


If I remember correctly it's something to do with DocumentProperty. I think the custom properties are a bit tricky - but im sure you'll figure it out.

Stew
 
Take a look at the Startup module within the example DB of Northwind that comes with MS Access.

This is where I figured how to create and reference custom database properties...
 
1. Go to Tools/References/Microsoft and check DAO 3.X. This is a quick fox, you should learn the ADO model.

2. Evryywhere you have reference to a database object, precede it with DAO. Ex: Dim RST as DAO.Recordset

As far as database properties. This'll get you to the Summary Info. Sames as file/database properties, Summary tab

Dim dbs As Database
Dim cnt As Container
Dim doc As Document
Dim prpLoop
Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set doc = cnt.Documents!SummaryInfo
With Doc.
'Your code here
End With
Set dbs = nothing
Set cnt = nothing
Set doc = nothing

I haven't been able to get to the custom properties programatcially. However, you can create your own property and append it to the collection.
 
Here's how to create a database property:

Dim db As Database
Dim prop As Property
Set db = CurrentDb()
Set prop = db.CreateProperty("yourProperty", dbText, "yourValue")
db.Properties.Append prop

---
Replace the string yourProperty with a name of your choice and yourValue with the text you want in this property.

To reference this property, use this to check the value:

CurrentDb().Properties("yourProperty") = "yourValue"

---

Hope this helps
 
Thanks a lot for trying to help.

I have had time to do some testing and a lot of reading.

It turns out that CurrentDB does for some reason not work with an Access Database Project file (.adp) although the documentation says otherwise. If have tested my code with a jet database (.mdb) and it works fine. If you have made this work please let me know, i've been using DAO 3.6 with MSDE/SQLServer 7.0 SP2 and Access 2000 SP1.

So I can't use DAO and have to use ADO (I agree with 'Databaseguy' that this is better, but i happened to know the basics of DAO).

I have managed to add a property via VBA and read it back by using the CurrentProject.Properties collection, but i haven't found a way to get at the one defined via the Access 'File' menu (neither standard nor user-defined) so help with this is still welcome.

Michel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top