Open MS Access from Visual Basic Form

Can I place a control (button) on a VB form that will launch an Access application? If so, how is that done?
LVL 11
EMCITAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Sure.  

In your VB Editor screen you should see a command button icon.  Click on the command button icon, then click-and-hold where you want the upper left of the button, drag to where you want the lower right of the button, then release.  You should see a command button.
Double-click on the command button to get to the VB Code Editor.  

You should see this in code...

Private Sub Command1_Click()

End Sub

... now modify it to look like this...



   
Private Sub Command1_Click()
Dim v

Dim sAccess As String
Dim sYourApp As String

sAccess = "c:\Program Files\Microsoft Office\Office\msaccess.exe"   '<--- Change if you are using a version higher than A2K
sYourApp = "c:\db1.mdb"   '<-- Change to wherever your app is

v = Shell(sAccess & " " & sYourApp, vbMaximizedFocus)

End Sub


Save, then run.

Hope this helps.
-Jim


0
 
pradapkumarCommented:
Yes you can do it.
On Click event of that command button call the executable file name using shell command.
Normally the access executable file is stored in C:\Program Files\Microsoft Office\Office10\.
you can call that executable using the following command for example

Shell "C:\Program Files\Microsoft Office\Office10\MSACCESS"

the above example calls the msaccess executable(i.e. application) for MS Office XP.

please check the application's executable location according to your version.

@};-
0
 
pradapkumarCommented:
oops little bit slower response.
0
 
rockiroadsCommented:
I prefer the use of the API call ShellExecute

http://www.vbaccelerator.com/codelib/shell/shellex.htm

Specify full pathname of file and it will open it using the registered program
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.