Running Word Document (1 Viewer)

Knight

Registered User.
Local time
Today, 11:42
Joined
Aug 19, 2002
Messages
20
I've put together a brief help/tutorial in word on how to use the database, and I want users to be able to open it by clicking a command button on the form.

I'm not sure whether to use a macro of VB, I've tried both and seem to be having similiar problems. When I tried in VB, I received the error message "File Not Found" after for the string entering:

"Word.exe Z:\FileName.doc"

And I tried the same thing for the argument in the macro.

I think I need a run command before "Word.exe" but I'm not sure what it is, and simply putting "Run or RunApp" didn't work.

Can anyone help?

Thanks
 

Travis

Registered User.
Local time
Today, 08:42
Joined
Dec 17, 1999
Messages
1,332
You could use VBA and the Shell function

Call Shell("Z:\FileName.doc")


I prefer to use the ShellExecute API

Code:
'Add this to a new module
Public 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

Public Function OpenFile(ByVal sTmpFile as string) As Boolean
   ShellExecute(0, "open", sTmpFile, 0, 0, 1)
   OpenFile=True
End Sub

Call this from a macro using "RunCode", The function name would be "=OpenFile("Z:\FileName.doc")
 

ghudson

Registered User.
Local time
Today, 11:42
Joined
Jun 8, 2002
Messages
6,194
The FollowHyperlink method is a simple way to open files using the OnClick event...

FollowHyperlink ("Z:\FileName.doc")

HTH
 

Knight

Registered User.
Local time
Today, 11:42
Joined
Aug 19, 2002
Messages
20
Thanks for the response, but I'm not sure I fully understand.

Travis, where do I put the file extension in that code, I haven't worked with modules before.

and ghudson, where do I put that bit of code you gave me? In VB or right in the On Click space?



thanks
 

Knight

Registered User.
Local time
Today, 11:42
Joined
Aug 19, 2002
Messages
20
Thanks a lot everyone. Disregard the above post because I figured it out.


My confusion with the hyperlink code was that I was copying the HTH into it, and that was my problem. Thank you also travis for your shell code.

Thanks!
 

Users who are viewing this thread

Top Bottom