Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 25th, 2006, 03:37 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Launching a program/open a file through VBA

I want to use VBA in Access to launch a seperate program. An example is that if a command button is pressed it would open up a specific Word document. It doesn't have to be word just any outside program. Does anyone have any suggestions.

Thank
Mike

Reply With Quote
  #2 (permalink)  
Old February 25th, 2006, 06:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

Hi Mike,

The Shell function is a quick way to open an execuatable from VBA. The following functions open a document in Wordpad, Notepad, and Word respectively.

' Call OpenWordPad("c:\document.rtf")
Public Function OpenWordPad(strFile As String)
     Dim x As Variant
    'C:\WINDOWS\SYSTEM32\write.exe
    x = Shell("write.exe " & strFile, 1)
End Function

' Call OpenNotePad("C:\document.txt")
Public Function OpenNotePad(strFile As String)
     Dim x As Variant
    'C:\WINDOWS\SYSTEM32\notepad.exe
    x = Shell("notepad.exe " & strFile, 1)
End Function

' Call OpenWord("C:\document.doc")
Public Function OpenWord(strFile As String)
     Dim x As Variant
    'C:\WINDOWS\SYSTEM32\WINWORD.exe
    x = Shell("WINWORD.exe " & strFile, 1)
End Function

The windowstyle argument value of 1 is the value of the vbNormalFocus constant. See the online help for other constant values.

HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old February 28th, 2006, 03:10 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That deffinatly helps but I think that I want to open up the snapshot viewer as opposed to any of those other programs you have listed. i'm running into a problem trying to get the OpenSnap function to work because it can't seem to find SnapView.exe. Is there another .exe I should be using. Here is my code.


 Call OpenSnap("h:\Snapshots\TempSnap.snp")
Public Function OpenSnap(strFile As String)
     Dim x As Variant
    'C:\Program Files\Snapshot Viewer\SNAPVIEW.exe
    x = Shell("SNAPVIEW.exe " & strFile, 1)
End Function

I also tried changing
 x = Shell("SNAPVIEW.exe " & strFile, 1)
to
 x = Shell("C:\Program Files\Snapshot Viewer\SNAPVIEW.exe " & strFile, 1)
But that didn't work.

Any help would be appreciated.

Reply With Quote
  #4 (permalink)  
Old February 28th, 2006, 04:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

Not quite sure why:

Code:
x = Shell("C:\Program Files\Snapshot Viewer\SNAPVIEW.exe " & strFile, 1)
doesn't work, unless "h:\Snapshots\TempSnap.snp" can't be found or accessed. It works fine on my end.

You do want to specify the path as you have, or Shell just looks for the exe along paths specified by the PATH Environment Variable in your system settings, which include (by default) %SystemRoot%\system32 (typically C:\WINDOWS\SYSTEM32) and %SystemRoot% (typically C:\WINDOWS).

Try:

Code:
Public Sub OpenSnapShotViewer()
    Dim x As Variant
    Dim Path As String
    Dim File As String

    Path = "C:\Program Files\Snapshot Viewer\SNAPVIEW.EXE"
    File = "h:\Snapshots\TempSnap.snp"

    x = Shell(Path + " " + File, vbNormalFocus)

End Sub
in case ther is a typo or something involved somewhere. I had no problem with:

Code:
Public Sub OpenSnapShotViewer()
    Dim x As Variant
    Dim Path As String
    Dim File As String

    Path = "C:\Program Files\Snapshot Viewer\SNAPVIEW.EXE"
    File = "E:\SecuredDatabase.snp"

    x = Shell(Path + " " + File, vbNormalFocus)

End Sub
Bob

Reply With Quote
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
run a program with VBA wdepreter Excel VBA 8 February 7th, 2007 08:33 AM
asp can't open db when db open by other program datuk Classic ASP Professional 3 June 13th, 2006 07:10 PM
Need Help launching crystal report file with in Po kspiderman Assembly Language 0 November 28th, 2005 10:16 PM
open a formatted excel file from program darvarin C++ Programming 1 June 15th, 2005 04:24 AM
Open email program speedyH ASP.NET 1.x and 2.0 Application Design 7 June 10th, 2004 12:41 AM



All times are GMT -4. The time now is 12:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.