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

RunApp Command Lines in MS Access

Status
Not open for further replies.

Wannabeegeek

Technical User
Jul 13, 2002
9
GB
I am trying to use the runapp command to open a MS Word document from MS Access. The word document name part of the command line to which needs to be speciefed by the user entered value in the field of a record.

Any solutions would be greatly appreciated.
 
How are ya Wannabeegeek . . . . .

[blue]RunApp[/blue] can only be run from a macro! I've never used it but in the [blue]command line window[/blue] try:
Code:
[blue]WinWord.exe "Drv:\Path\FileName"[/blue]
For [blue]VBA[/blue] use the [purple]Shell Function[/purple].

Calvin.gif
See Ya! . . . . . .
 
Thanks for that but I've got that far. My problem is that I want the filename to be taken from a user entered value in one of the fields in a record. It's so the user, who can see a continuous form, can enter values in one of the fields. Then at the end of each record there is a button which when clicked opens the file named in the field in that record.

Any ideas would be greatly appreciated.
 
OK Wannabeegeek . . . . .

Then your gonna have to use the VBA [blue]Shell Function[/blue]. You can just about any event you like or use a command button to call the following function (you substitute [purple]purple[/purple] items):
Code:
[blue]Public Sub OpenDoc()
   Dim WordPath As String, DocPath As String
   Dim FileName As String, FullSpec As String
   
   WordPath = "[purple][b]Drv[/b][/purple]:\[purple][b]Path[/b][/purple]\WINWORD.EXE"
   DocPath = "[purple][b]Drv[/b][/purple]:\[purple][b]Path[/b][/purple]\"
   FileName = Forms![purple][b]YourFormName[/b][/purple]![purple][b]YourControlName[/b][/purple]
   FullSpec = WordPath & " " & DocPath & FileName
   
   Shell FullSpec, vbMaximizedFocus
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Very many thanks but I must inform you that I know what VBA stands for and little else. I set the properties 'on click' to Event Procedure and entered the code exactly as you wrote it above but when I click the button I get the following error message:

The expression on click you entered as the event property produced the following error: Invalid Outside Procedure.
* The expression you entered may not result in the name of a macro, the name of a user defined function or Event Procedure.
* There may have been an error evaluating the function, even or macro.

Please can you tell me what I'm doing wrong.

Cheers.
 
Wannabeegeek . . . . .

Post the code as you have it now!

Calvin.gif
See Ya! . . . . . .
 
CODE
Private Sub NUM_Click()

End Sub
Public Sub OpenDoc()
Dim WordPath As String, DocPath As String
Dim FileName As String, FullSpec As String

WordPath = "C:\Documents and Settings\user1\Desktop\New Folder\WINWORD.EXE"
DocPath = "C:\Documents and Settings\user1\Desktop\New Folder"
FileName = Forms!TEST!WORDNUM
FullSpec = WordPath & " " & DocPath & FileName

Shell FullSpec, vbMaximizedFocus
End Sub
 
OK Wannabeegeek . . . . .

If you look at it and imagine concatenation, there's a missing backslash [purple]\[/purple] at the end of [blue]DocPath[/blue] which I show in my origional code:
Code:
[blue]DocPath = "C:\Documents and Settings\user1\Desktop\New Folder"
Should be:
DocPath = "C:\Documents and Settings\user1\Desktop\New Folder[purple][b]\[/b][/purple]"[/blue]
Next . . .
Wannabeegeek said:
[blue]The expression on click you entered as the event property produced the following error: Invalid Outside Procedure.[/blue]
This indicates that you entered the code in the event line!

To be sure, put the cursor on the event line, then click the three elipses jst on the right. This will take you to the VBE window and the click routine. I'm sure you know what to do from here . . .

One other thing . . . . I query the location of [blue]WordPath![/blue]. [purple]This is not the normal office folder[/purple]. It should be something like: [blue]"C:\Program Files\Microdoft Office\Office\WINWORD.EXE[/blue] This is the actual/perferred location, as [blue]its possible to use cleanup software that will wipe your WordPath out![/blue]

Give it a whirl and let me know . . . .


Calvin.gif
See Ya! . . . . . .
 
You could also try this wrapper for the ShellExecute API, just drop the code into a standard mocule (not a forms/reports module), and call it like in the samples within the code. No need to specify the application path, it will open the specified document with the assosiated application. Start an app with ShellExecute

Roy-Vidar
 
Hi,

For common file types specially MS Office files, I found that using Hyperlink is also quite effective. Infact its' beauty is that you can run multiple types of files without specifying the programs associated with it. I am using something like this.

Dim strPath as String

'Define the path of file
strPath = Me.LstFiles.Column(1) & "\" & Me.LstFiles

Application.FollowHyperlink strPath, , True, False

In the above file I am using a list box for my pwn find files utility in access. Colum 1 contains folder name, while colum 2 contains filename.

Cheers!
ÙÇãá

It's important to learn the rules so that you know how to break them.
 
Just out of interest to anyone else trying to do what I was trying, this is how I did it.

It's might be worth noting that the best way I found to active the module was to click on the ... at the end of the on_click line in the properties window and use the expression builder to lead to the module.

Option Compare Database

'------------------------------------------------------------
' TEST
'
'------------------------------------------------------------
Function TESTER()
On Error GoTo TEST_Err

Call Shell("WINWORD.EXE ""C:\Documents and Settings\user1\Desktop\New Folder\" & Forms![TEST]![Number] & ".doc""", 1)


TEST_Exit:
Exit Function

TEST_Err:
MsgBox Error$
Resume TEST_Exit

End Function
 
Related problem:
How would I open an EXCEL file that is named the Concatenation of 3 fields in my DB? I tried this on my home PC & it worked using hyperlink (local files) - at work (onthe network I can't get it to work).

Basically, in a query I concat Field A and Field B and Field C, store this as a FIELD 1 in the same table as Fields A/B/C, make FIELD 1's datatype 'hyperlink', then put that FIELD 1 into a text box on the FORM. Worked before, can't get it to work now with network files.

Any ideas?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top