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

OpenCurrentDatabase Method. 1

Status
Not open for further replies.

jmgibson

Technical User
Oct 1, 2002
81
US
I am trying to use the code below to open the current database. My originial intention was to to store this file that contains the code below in the same directory as the database listed; therefore, not specifying the entire path.

Dim accObj As New Access.Application
accObj.OpenCurrentDatabase "reservecalc tracking tool.mdb"


When the code runs, it looks for this mdb in what every folder the user has their Default Database Folder set to.
Since multiple users have saved this file in different places (different folders on different networks), it returns an error stating "file not found." Is there a way to have it look in the directory where the file containing the opencurrentdatabase command resides?

 
If you are using Access 2000 or Greater:

accObj.OpenCurrentDatabase Application.CurrentProject.Path & "\reservecalc tracking tool.mdb"

If you are using Access 97 (I'm not sure if there is an easier way than this but, it's always worked for me):

Dim Cdbs As String, dbs As String, Cdir As String
dbs = "ThisDBName.mdb"
Cdbs = CurrentDb.Name
Cdir = Left(Cdbs, InStr(Cdbs, dbs) - 1)

accObj.OpenCurrentDatabase Cdir & "reservecalc tracking tool.mdb"

Change ThisDBName.mdb to "file containing the opencurrentdatabase command".

Regards

Bill


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top