Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 3rd, 2003, 08:41 PM
amidala amidala is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bukit Kerinchi
Posts: 12 amidala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 7th, 2003, 05:34 PM
atightdude atightdude is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 6 atightdude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old September 9th, 2003, 01:44 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Thumbs up

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Open Access file from VB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway