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

Open Microsoft Access from Visual Basic

Status
Not open for further replies.

speltrain

Technical User
Apr 29, 2003
17
0
0
US
I am trying to find a command that will allow me to open an Access 2000 database and then close the VB form.

I can't figure out a way to do this for opening the database but got it to work with running a batch file. I tried to just have the batch file do it, but the batch file will do everything but open the database. Can anyone Help?
 
Try ShellExecute

It's been covered in the forum several times recently


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I've been searching the forum for a couple of days, can someone at least give me some kind of code to start out with that is understandable. The MSDN example doesn't make any sense. All I need to the code to do is open a microsoft access database, that's it.

Thanks in advance
 
Private 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
Private Sub Command1_Click()
res = ShellExecute(hWnd, vbNullString, "J:\Palletags\Palletags.mdb", vbNullString, vbNullString, vbNormalFocus)
If res = 31 Then
MsgBox "This file is not associated with a program!", vbCritical, "File Association Error"
Exit Sub
End If
End Sub

Swi
 
I cannot get this code to work by replacing the path to my database in the path provided. When I click the button nothing happens, what am I missing here? Sorry to be a pain, I'm new to this end of VB.
 
The usage shown above assumes that the default verb associated with the file type is "Open", and that is usually the case. To be sure that isn't the problem, you can change the above code from:
res = ShellExecute(hWnd, vbNullString, "J:\Palletags\Palletags.mdb", vbNullString, vbNullString, vbNormalFocus)

to:
res = ShellExecute(hWnd, "Open", "J:\Palletags\Palletags.mdb", vbNullString, vbNullString, vbNormalFocus)


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks for your help everyone, The problem was my fault, had the wrong path.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top