Tell access to use the current directory

S

Steven

I have a file OpenFile.mde that opens another file mdb that has is password
protected.

Dim db As DAO.Database
Dim strDbName As String
strDbName = "C:\Acct\Access\GLFile.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=pwd")
acc.OpenCurrentDatabase strDbName

Question: Instead of saying "C:\Acct\Access\GLFile.mdb" How do I say just
use the directory you are currenly in (ie the OpenFile.mde and GLFile.mdb are
in the same directory?

Thank you,

Steven
 
D

Douglas J. Steele

Realistically, you can seldom be sure of what the current directory is (it
won't be the same directory as the currently-open database unless you opened
Access and used File | Open to navigate to the database).

However, you can easily determine where the currently-open database is using
CurrentProject.Path:

strDbName = CurrentProject.Path & "\GLFile.mdb"

(Note that the Path property does not include the terminating slash, so you
need to add it to the file name.)
 
S

Stuart McCall

Steven said:
I have a file OpenFile.mde that opens another file mdb that has is password
protected.

Dim db As DAO.Database
Dim strDbName As String
strDbName = "C:\Acct\Access\GLFile.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=pwd")
acc.OpenCurrentDatabase strDbName

Question: Instead of saying "C:\Acct\Access\GLFile.mdb" How do I say
just
use the directory you are currenly in (ie the OpenFile.mde and GLFile.mdb
are
in the same directory?

Thank you,

Steven

strDbName = CurrentProject.Path
 

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