Opening another Access db with variable name from same folder

D

danlin99

Can someone tell me how to write a vba code to open an Access application
(MyApp2_rev_n.mdb) from the same folder as my current project (MyApp1.mdb) as
shown in the example below. MyApp2_rev_n.mdb is rev controlled and the name
is stored on zDbName table in MyApp1.mdb. Thanks for the help.

current project path
c:\folder1\folder2\myProjYYYYMMDD\MyApp1.mdb

database I want to open
c:\folder1\folder2\myProjYYYYMMDD\MyApp2_rev_n.mdb
 
S

Stuart McCall

danlin99 said:
Can someone tell me how to write a vba code to open an Access application
(MyApp2_rev_n.mdb) from the same folder as my current project (MyApp1.mdb)
as
shown in the example below. MyApp2_rev_n.mdb is rev controlled and the
name
is stored on zDbName table in MyApp1.mdb. Thanks for the help.

current project path
c:\folder1\folder2\myProjYYYYMMDD\MyApp1.mdb

database I want to open
c:\folder1\folder2\myProjYYYYMMDD\MyApp2_rev_n.mdb

Dim strAppPath As String

strAppPath = CurrentDb.Name
strAppPath = Left(strAppPath, InstrRev(strAppPath, "\"))
Debug.Print strAppPath & MyApp2_rev_n.mdb
 
D

danlin99

Hi Stuart,

Thanks for the quick response. I tried this code but it will not open the
second db. Also, I don't want to hardcode the name of the db I'm opening
because the revision number changes. I want to get it from table 'zDbName'.
It's even better if there's a way to get the full name of the db name just by
supplying the first 11 letters like '2_SCM_SNPID'.

Dim strAppPath As String
strAppPath = CurrentDb.Name
strAppPath = Left(strAppPath, InStrRev(strAppPath, "\"))
'Debug.Print strAppPath & MyApp2_rev_n.mdb
Shell """C:\Program Files\Microsoft Office\Office11\MSAccess.exe"" " & _
strAppPath & "2_SCM_SNPIDAssessment_TOOL_v02_11_D.mdb"
 
J

John Spencer

You might try FollowHyperLink command

So if you have the full path name in a string or can build it using
something like the following

strOpenDb = CurrentProject.Path & "\" & DLookup("dbName","zDbName")

FollowHyperLink strOpenDb


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
D

danlin99

Thanks a lot, John. It worked.

John Spencer said:
You might try FollowHyperLink command

So if you have the full path name in a string or can build it using
something like the following

strOpenDb = CurrentProject.Path & "\" & DLookup("dbName","zDbName")

FollowHyperLink strOpenDb


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

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