Calling an external file from a command button

J

Joanne

Hello,
I have a command button on a form and with the "On Click" event it runs the
following code:

Dim RetVal
RetVal = Shell("C:\documents and settings\jjones\desktop\POBlank.nrl", 1)

The nrl file type is associated with a viewer (view32.exe) from a company
called Interwoven. I get a runtime error 5 " Invalid procedure call or
agrument" but if I click on the file on my desktop it works fine and if I
copy the path and use the run command from my start menu it also works fine.
Any help would be greatly appreciated.
 
F

fredg

Hello,
I have a command button on a form and with the "On Click" event it runs the
following code:

Dim RetVal
RetVal = Shell("C:\documents and settings\jjones\desktop\POBlank.nrl", 1)

The nrl file type is associated with a viewer (view32.exe) from a company
called Interwoven. I get a runtime error 5 " Invalid procedure call or
agrument" but if I click on the file on my desktop it works fine and if I
copy the path and use the run command from my start menu it also works fine.
Any help would be greatly appreciated.

What happens if, instead of using Shell you use:

Application.FollowHyperlink "C:\documents and
settings\jjones\desktop\POBlank.nrl"
 
J

Jack Leach

You can try using the Shell function with no return:

Shell "C:\blahblah.file", 1



Or, (my preferred method), use the ShellExecute API found at mvps.org:

http://www.mvps.org/access/api/api0018.htm

For the record, the second argument here can be changed to "print" instead
of vbNullString. This may be an optional argument for vba's regular old
Shell() function, but I'm not sure (a wrapper function is recommended for
ease of use).


Or, you can use Application.Followhyperlink, though I personally tend to
avoid this one. It seems as though your operating system treats files called
this way as a hyperlink (makes sense, right?). Unfortunately, the OS has
security features against opening certain files this way. I've come across
at least one filetype that could be opened by ShellExecute but not
Application.Followhyperlink, and hence, my preferred method is the
ShellExecute API.


I am of the suspicion that these various subtleties are dependant open how
the operating system receives the command. I think
Application.FollowHyperlink gets trouble because the system wants to open it,
as a hyperlink, which could have been a request sent from anyone or anything.
Shell() may be a bit better off than that... at least its coming from a
trusted application. ShellExecute, being an API, works directly on a system
level and doesn't seem to cause issues. (this last paragraph is completely a
guess... but I think it's pretty close. Certain files opened with
FollowHyperlink causing problems is not a guess.)


If it is absolutely imperitive that you have a return value, unfortunately
I've never been in that situation and hence am not sure how to do it. You
might try explicitly declaring the variable as a Variant or Double datatype.

Dim RetVal As Variant
RetVal = Shell("yourpathandfile", 1)



hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top