Dir Function

B

box2003

I created a database in .mdb format and want to distribute locally in .mde
format. Part of my code below checks for either the .mde or .mdb format and
opens the database accordingly. Is this a correct method or is there a
better way. The purpose is to allow me to test and develop this application
in .mdb format and then create the .mde format and still have the
application run in either formats.

If Dir("C:\Customer Info\customer.MDB") <> "" Then
Set dbsCustomer = OpenDatabase("C:\Program Files\Customer
Info\Customer.mde")
else
Set dbsCustomer = OpenDatabase("C:\Program Files\Customer
Info\Customer.mdb")
End If
 
W

Wayne Morgan

While you can do what you have, the <> should be = and "Program Files" is
missing from the Dir(). Also, I would actually recommend verifying that the
file exists at all, not just assume that because the mdb file isn't there
that the mde is.

strFileName = Dir("C:\Program Files\Customer Info\customer.MD?")
If strFileName <> "" Then
Set dbsCustomer = OpenDatabase("C:\Program Files\Customer Info\" &
strFileName)
End If

Also, are you installing in "C:\Program Files" or are you installing in the
defined Program Files folder (i.e. Windows wasn't installed on the C:
drive). If the latter, you would need to do an API call to get the defined
folder. You could also check for the "ProgramFiles" environment variable.
The API call is preferable.
 
B

box2003

You have raised an interesting point I had not even considered about
"Program Files" folder in the program installation and the API call. Would
you be able to direct me to the API syntax that would check for the program
installation?

Thanks
 
W

Wayne Morgan

PS,

One correction to the code listed. I show the constant CSIDL_PROGRAM_FILES
should be &H26, not &H2A. At least it is for WinXP on my computer.
 
A

Albert D.Kallal

Is not your application split, and the tables accessible by a linked table?

You might actually want to remove that hard coded path name anyway......

If you database is split, and the data is always distribute as a mdb file,
only your code part would be a mde.....
 

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