|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Open Access file from VB
Hi,
The code below is for opening Access application from VB. Can I specify to which Access file that I want to open?For example: I need to open Query.mdb from VB. How can I do this? Private Sub btnAccess_Click() On Error GoTo Err_Command2_Click Dim oApp As Object Set oApp = CreateObject("Access.Application") oApp.Visible = True On Error Resume Next oApp.UserControl = True Exit_Command2_Click: Exit Sub Err_Command2_Click: MsgBox Err.Description Resume Exit_Command2_Click End Sub |
|
#2
|
|||
|
|||
|
Open access file
I would suggest using the shell statement.
This will open the program: Shell "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" If you want to have the program load with the file in it, use this: Shell "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" "C:\My Documents\Query.mdb" So, you could say something like this: location = Chr(34) + "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" + Chr(34) file = Chr(34) + Text1.Text + Chr(34) Shell location + " " + file, vbNormalFocus Excel would open the file that was entered in Text1. I used Chr(34) because this returns a value of the quotation mark " . You must have the quotation mark to run the application specified. The " " in the last line of code is actually a space to seperate the location and file. This is a little confusing, but will make since after you mess around with it a little. Hope this helps, Brady |
|
#3
|
|||
|
|||
|
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
'Runs the files associated program Private Function MyShell(PathAndFile As String, Optional Parameters As String = "", Optional ShowCmd As Long = vbNormalNoFocus) As Long Dim Path As String Dim File As String 'Get everything up to and including the last backslash Path = Left(PathAndFile, InStrRev(PathAndFile, "\")) 'Make absolutely sure there's no baskslashs on the end :-) While (Right$(Path, 1) = "\") Path = Left(Path, Len(Path) - 1) Wend 'Grab everything from the last backslash, on to the end File = Mid$(PathAndFile, InStrRev(PathAndFile, "\") + 1) 'Grab the results of the API Call MyShell = ShellExecute(0, vbNullString, File, Parameters, Path, ShowCmd) 'If there's an error, let's try VB's Shell 'If this doesn't work, it will yell out an error If MyShell < 32 Then Shell PathAndFile, ShowCmd End Function Private Sub comand1_DblClick() 'If they double-click a file, run the associated program '(look below for how this is done) MyShell filename, vbNormalFocus End Sub |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Open Access file from VB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|