Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2006, 03:37 PM
Registered User
 
Join Date: Dec 2005
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

 
Old February 25th, 2006, 06:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 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

 
Old February 28th, 2006, 03:10 PM
Registered User
 
Join Date: Dec 2005
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.

 
Old February 28th, 2006, 04:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 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






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 06: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 03:24 AM
Open email program speedyH ASP.NET 1.x and 2.0 Application Design 7 June 9th, 2004 11:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.