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!

New to VB and need help with automation.

Status
Not open for further replies.

JennW

IS-IT--Management
Jan 30, 2001
39
0
0
US
I am trying to make my command button open up a file in Microsoft Access. I know this must be pretty simple and I have tried multiple things in my private sub, but nothing seems to work. Is there a code somewhere that can help me?

thanks for your patience and help.

JennW
 

'API to Launch other programs / files
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



'Sample routine
Private Sub Command1_Click()
On Error GoTo ErrorHandler
ShellExecute hwnd, "open", "C:\My Documents\Some.mdb", vbNullString, vbNullString, conSwNormal
Exit Sub
ErrorHandler:
MsgBox Err.Number & " " & Err.Description, vbCritical, "Encountered Following Error"
Exit Sub
End Sub
 
If you don't want to mess with the API, go to Project>>References then add a reference to Microsoft Access 8.0 Object Library. Now you can create an access object:
Dim objAccess As Access.Application
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase ("C:\dbName.mdb")

Then do whatever you want with it:
objAccess.DoCmd.OpenReport "ReportName", acViewPreview
objAccess.DoCmd.OpenForm "FormName"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top