View Full Version : Open Database from Form


Kinger43
01-07-2008, 09:57 AM
Is it possible to open a database from a form in a different database? Not necessary to do so; it would just be handy to do from the form I already have up and looking at rather than having to go open another instance of access and go to that database.

pbaldy
01-07-2008, 10:09 AM
You could use Shell or FollowHyperlink. More info on both in VBA Help.

Kinger43
01-08-2008, 06:24 AM
Public Function OpenDatabase()
On Error GoTo Err_OpenDatabase

Dim database
Dim turtlemeter As String
turtlemeter = "s:/AccessDB/Turtle_Meter"
database = Shell(turtlemeter, vbNormalFocus)

Exit_OpenDatabase:
Exit Function

Err_OpenDatabase:
MsgBox Err.Description
Resume Exit_OpenDatabase

End Function

I call this function from a form with a button click. It gives me a File not found message. I know the file is there, can anyone tell me what may be wrong?

Rabbie
01-08-2008, 06:27 AM
Have you tried

turtlemeter = "s:/AccessDB/Turtle_Meter.mdb"

Make sure you have the full name of your db file.

Kinger43
01-08-2008, 06:29 AM
Says "Invalid procedure call or argument"

Rabbie
01-08-2008, 06:38 AM
You going to have to tell shell to use Ms Access to open your file so try

turtlemeter = " C:\ path to Acces\msaccess.exe s:/AccessDB/Turtle_Meter"

Remember that your DB is not a executable file - it is a datafile for msaccess to use.

Kinger43
01-08-2008, 06:48 AM
That didn't work either. I tried just opening access without the database and it wouldn't do that either. It just said file not found. I'm new with VB so I really don't know what all capabilities I have with it. I figured this would be a good learning experience but it has become more of a challenge than I expected.

Rabbie
01-08-2008, 06:50 AM
That didn't work either. I tried just opening access without the database and it wouldn't do that either. It just said file not found. I'm new with VB so I really don't know what all capabilities I have with it. I figured this would be a good learning experience but it has become more of a challenge than I expected.
Try looking at Followhyperlink. That might be a better solution for you. There is info in VBA help.

pbaldy
01-08-2008, 07:40 AM
Here's a working example:

Dim intTest As Integer

intTest = Shell("C:\Program Files\Microsoft Office\Office\winword.exe C:\AccessAp\test.doc", vbNormalFocus)