PC Review


Reply
Thread Tools Rate Thread

Calling an external file from a command button

 
 
Joanne
Guest
Posts: n/a
 
      3rd Jun 2009
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.
 
Reply With Quote
 
 
 
 
fredg
Guest
Posts: n/a
 
      4th Jun 2009
On Wed, 3 Jun 2009 15:35:01 -0700, Joanne wrote:

> 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"
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
Jack Leach
Guest
Posts: n/a
 
      4th Jun 2009
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)



"Joanne" wrote:

> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a subroutine with a command button JonV Microsoft Excel Programming 2 7th Jul 2008 10:45 PM
Calling command button from another sheet Ian Microsoft Excel Programming 4 13th Apr 2006 07:41 PM
Command Button to Open EXTERNAL file (any kind) =?Utf-8?B?RGF2aWRHdWFtYW4=?= Microsoft Access 4 9th Sep 2005 10:21 PM
Calling a command button on a differnet form... Brad Pears Microsoft Access Form Coding 2 9th Jun 2005 06:16 PM
Calling a command button perico Microsoft Access Form Coding 2 30th Sep 2003 10:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:16 PM.