quick easy question (1 Viewer)

binghamw

BingleyW
Local time
Today, 09:02
Joined
Apr 22, 2004
Messages
57
Does anyone know how to make a command button on a form open up another MS Access database. I know this is so easy but I can't figure out how to do it.
 

JC10001

Registered User.
Local time
Today, 17:02
Joined
Sep 24, 2003
Messages
48
binghamw said:
Does anyone know how to make a command button on a form open up another MS Access database. I know this is so easy but I can't figure out how to do it.

Create a new module with this code.
Option Compare Database
Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long

Global Const SW_SHOWNORMAL = 1


Save it as "Shell_Execute".

Add the following function to your form.


Function Open_Document(DocName As String)
On Error GoTo Open_Document_Error

StartDoc = ShellExecute(Application.hWndAccessApp, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL)
Exit Function

Open_Document_Error:
MsgBox "Error: " & Err & " " & Error
Exit Function
End Function


In the click command for your button type

dim file_path as string
file_path = "C:\whatever\whatever.mdb"

Open_Document(file_path)



This should work.
 

ghudson

Registered User.
Local time
Today, 12:02
Joined
Jun 8, 2002
Messages
6,195
There are a few ways to do this. I prefer either of these two...

You could use the Shell() function
Code:
Call Shell("X:\YourDatabase.mdb", vbNormalFocus)
Or you can use the Application.FollowHyperlink method
Code:
Application.FollowHyperlink "X:\YourDatabase.mdb"
 

JC10001

Registered User.
Local time
Today, 17:02
Joined
Sep 24, 2003
Messages
48
Wow. You're way is much simpler. I'd definitely go with that instead.

Hey, ghudson, since you're so smart would you mind taking a look at my thread entitled "Form import woes" a few topics down?
 

binghamw

BingleyW
Local time
Today, 09:02
Joined
Apr 22, 2004
Messages
57
thanks. I used the application hyperlink and it worked perfectly.
 

Users who are viewing this thread

Top Bottom