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

Open an Access Database from within Visual Basic

Status
Not open for further replies.

sspainhour

IS-IT--Management
Jan 8, 2002
9
US
I have a Visual Basic application with a database backend. I have used Active Tool Bars for the toolbar. I would like to put a button on the toolbar that will open and run a seperate access database application that is designed for insurance quoting. Is it possible, and what is the exact code? I have already created a button on the toolbar and told it to call DoQuotes(), however, I do not know how to create a Private Sub that will open and run an access database called quotes.mde.
 
The shellexecute api call is usually pretty popular for doing things like that.


Here is shell execute's declaration:

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


Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9


you would call Shellexecute with code similar to this:

shellexecute(Me.hwnd, "Open", "path\quotes.mde", _
"-fast", "C:\MyProg\", SW_MAXIMIZE)


Hope this helps
Josh
 
Thank you. That is very helpful, however, I am having some problems. I declared the shellexecute function in my main module and I entered the Private Sub

Private Sub DoQuote()

shellexecute(me.hwnd, "\\ntserver\netdrv\quotes\quote.mde", _"-Fast", "C;\Program Files\Microsoft Office\Office\MSAccess.exe", SW_MAXIMIZE) As Long

End Sub

But when I run it, I get a compile error. "Statement invalid outside Type Block". I have searched the MSDN library and have played with the syntax, but I can not get it to work. Do you have any suggestions? Thanks.
 
Use this exact line:

dim intReturn as Integer

intReturn = shellexecute(me.hwnd, "Open", "\\ntserver\netdrv\quotes\quote.mde", _"-Fast", "C:\Program Files\Microsoft Office\Office\MSAccess.exe", SW_MAXIMIZE)

Also, please verify for me that you are trying access a file that is in a shared folder.

Good Luck!
Josh
 
OK, the declaration goes in the declarations section of your module (i.e before all your code, and after Option Explicit - you do have Option Explicit set, don't you?). Eg:
[tt]
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

Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9

' All your subs, functions, come after the above declarations
[/tt]
Then you call it slightly differently from the way that you have tried to:
[tt]
Public Sub DoQuote()
Dim hProcess As Long
hProcess = ShellExecute(Form1.hwnd, &quot;Open&quot;, &quot;<full path to you program goes here>&quot;, &quot;&quot;, &quot;&quot;, SW_RESTORE)
End Sub

[/tt]
 
That worked perfectly. Thank you so much for all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top