Wrath
March 31st, 2001, 08:47 AM
I need to connect to a local access97 db with vb6.
but the program should work on serveal different machines.
so how do i refer to my database.
dim db as Database
set db=OpenDatabase("mydb.mdb")
doesnt work even if the file mydb.mdb is in the current directory.
it works with the compiled exe file
but gives me an error saying that it couldnt find the file.
Does anybody now a soulution for this?
shree
March 31st, 2001, 09:01 AM
The syntax that you use looks for the file in the current directory. And don't assume that the current directory is the same as the one with the application. To make sure that it is, you can use
chdir App.Path
before using OpenDatabase. This makes the application path as the current directory and will look for the file here.
Otherwise, you can use
Set db = OpenDatabase(App.Path & "\mydb.mdb")
This also works, and it doesn't change the current directory.
vchapran
March 31st, 2001, 09:26 AM
If you are going to use separate db for each user, then you can use App.Path or hard coded path or write and read path to and from Registry or *.INI file, if the same db is going to be used by all users, then Map drive with that database on each user computer, let's say as "Z:" and then refer to it, as it was on the user computer. For example if db is on each computer, then it must be in the same location, like "C:\Program Files\MyProgram\Data\MyDB.mdb" (for hard coded scenario). Then in VB you use
private strDBName as string
strDBName = "C:\Program Files\MyProgram\Data\MyDB.mdb"
Dim db as Database
set db = OpenDatabase(strDBName)
You can use App object and its Path property, if database will be located in your program directory:
strDBName = App.Path & "\Data\MyDB.mdb"
set db =OpenDatabase(strDBName)
In case if db is on Mapped drive, use:
strDBName = "Z:\MyDatabaseFolder\MyDB.mdb"
set db = OpenDataBase(strDBName)
In case you read Database location from Registry, you write it to the Registry during the installation using either API functions (better, but more complicated) or VB functions (worse, but easier), then you read it into strDBName and use as above.
HTH
Vlad