Detecting Properties of a Database Programmatically

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 02:17
Joined
Jul 5, 2007
Messages
586
In another thread, I posted a question with some code.
A user was kindly able to assist me resolve that particular code, but the code solution I presented is not nearly the ideal solution for me.
Yes, it works, but I can’t help but think there is a more appropriate way to achieve the goal.

So, obviously databases have certain properties, for example their file format, among other things.

Older databases, Access 2002-03 format and earlier, may also be encoded.
I would love to be able to detect these attributes directly.

Right now, my code locates and attempts to convert a database.
If the database is encoded, it fires an alert, and my code reads the error to see if it is an encoded alert.
If it successfully converts the database, my code concludes the database must not be encoded and then deletes the freshly created converted version.
Yes, this works, but is clunky and slow. Plus there are other messages which can fire and the code has to read them all before it is convinced the database is encoded or not.

So, for example, I alternatively have this code which will open a database and check it’s file format.
Code:
Sub OpenAccessTest()
Dim AccessObj As Object
Dim AccessPathIn As String
Dim AccessPathOut As String
Dim FormatResult As String

AccessPathIn = "C:\Testing\MMDemoEnecoded.mdb"
AccessPathOut = " C:\Testing\MMDemoEncoded_2k7.accdb"

Set AccessObj = CreateObject("Access.Application")

AccessObj.Application.OpenCurrentDatabase AccessPathIn, True

Select Case AccessObj.Application.CurrentProject.FileFormat
Case acFileFormatAccess2
FormatResult = "Microsoft Access 2"
Case acFileFormatAccess95
FormatResult = "Microsoft Access 95"
Case acFileFormatAccess97
FormatResult = "Microsoft Access 97"
Case acFileFormatAccess2000
FormatResult = "Microsoft Access 2000"
Case acFileFormatAccess2002
FormatResult = "Access 2002 - 2003"
Case acFileFormatAccess12
FormatResult = "Microsoft Access 2007"
End Select
 
MsgBox "This is a " & FormatResult & " project."

AccessObj.Application.CloseCurrentDatabase
Set AccessObj = Nothing

End Sub
I can’t help but think there is a similar way to detect other attributes (or properties).
It would be GREAT to directly detect:
File version format (completed)
Encoded or not encoded
File password protected or not password protected
VBA Project password protected or not password protected

I am running Access 2010 (x86) so my available libraries are currently limited to those included with Office 2010.
I have dug and dug and searched the internet and help files.

If I know what library to obtain from prior versions, I can certainly get it/them.
The problem there is, I have no idea what to get.

So please guys and gals, I REALLY NEED the assistance of the masters here.
Is there some method or function or whatever, from Access 2010, OR EARLIER versions that I could use to gain this information directly?

Some clue where to look or what the method function is named?
Anything will help.
 
If you go to vba and open the immediate window and type:

Code:
?currentdb.Properties.Count
You should get something like 25. Then you can go through all 25 one at a time and see the names with:

Code:
?currentdb.Properties(0).name
Remember when using an enumerated reference start with 0 instead of 1 and in this case if there are 25 properties the top would be 24.

Once you know that property number 0 is 'Name' you can use either the enumeration value '0' or the property name ''Name" to see the actual property value:

Code:
?currentdb.Properties(0)

or 

?currentdb.Properties("Name")
In my case either method returns:

Code:
C:\Documents and Settings\340364\Desktop\Database1.mdb

Now that you know the property names you would then use like methods in VBA code. Hope this helps a little - :)

fyi - All of this, less the actual values, is available using the object browser :)

Edit - I forgot to mention that you can even create custom database properties!
 
Last edited:
THANKS KEN!
This was EXTREMELY interesting and a great exercise!

But alas, no joy on my quest to learn the desired attributes.

I was able to learn a lot though.
In the databases I was working with:
Access 2002-03 formatted DBs had 46 different properties
Access 97 formatted DBs had 32 different properties

I didn't spend any time checking 2k7 or 2k formatted files.


There was lots of neat info there, indeed, but not what I'm looking for.

I wrote some code to cycle through all the properties and write their names and values to a workbook, for both encoded and non-encoded (decoded?) workbooks and could not see any property based difference between them at all.

(if anybody is interested, or thinks it might be useful, I could post a table in a seperate thread)

So, my quest continues, but I fear I'm realistically out of time to chase this.

I still find it hard to imagine, other than waiting for an error when converting, we can't come up with some way to detect these properties programatically.

ANY OTHER IDEAS?
 

Users who are viewing this thread

Back
Top Bottom