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

Weird Shell error

Status
Not open for further replies.

faust13

Programmer
Aug 7, 2001
176
US
Okay, here's the snippet of code:
'Set the record set to Text4
Set Text4.DataSource = rsFileName
'Assign column data from the FileName column to Text4
Text4.DataField = "FileName"
'Compile the command line string for the Shell() command
strFileName = "d:\application\pdfs\" & Text4.Text
'Just double checking it here. Yup. it is exactly the same
'as I would type it from the command line (which does work)
MsgBox (strFileName)
'Run the shell
Shell (strFileName)

But it errors out with:
Run-time error '5':

Invalid procedure call or argument

AHHH!!! What is going on???

Thanks in advance! ----------------------------------------
Is George Lucas Kidding...
 
You have bad syntax on the Shell line. If you don't need the return value of shell, then call it as either
Call Shell(strFileName)
or use the procedure syntax
Shell strFileName
 
I tried:
Call Shell(strFileName)
Shell strFileName

Both generate that same error.

I double checked the value of strFileName at runtime, and everything is correct. It is exactly how I would open the file from the command line.

I just don't know what is going wrong here. ----------------------------------------
Is George Lucas Kidding...
 
I notice this:
Code:
'Assign column data from the FileName column to Text4
Text4.DataField = "FileName"

If FileName is a variable already holding a value, you don't need the quotes. Also, shouldn't it be 'strFileName', and not just 'FileName'.....isn't it the same 'FileName' variable used in the later lines??

Buffer0verflow
 
Buffer0verflow,

FileName is the literal name of a column in my query. I must "bind" the datasource and datafield to Text4.

I don't understand why this doesn't work Shell() is supposed to be exactly as you are typing it from the command line, right?

Why does it work when I open my command line, but not in my VB App? ----------------------------------------
Is George Lucas Kidding...
 
This may be a dumb question, but are you absolutely positive the error is being raised by the Shell(strFileName) line? I tried messing around with the shell command a little, and the only way I could get it to raise a run-time error 5 was when I passed it an uninitialized Variant as the argument (this is in VB6 SP5). Even with complete garbage as the command line, all I got was a "file not found" error.

I don't know if that's useful, but it might be something to think about. Also, another dumb question, but have you tried the old copy-and-paste testing method just to be sure? (You know, copy from the debug window to the command line, or vice versa. I'm always surprised how many mistakes I catch that way.)

I'm officially out of ideas now.
 
I'm nearly out of ideas too. I tried to cut and paste, I took the watch dump and pasted it into notepad, it is identical to the manually typed, working command line.

What I'm trying to do is query a database, get the pdf file name, and launch the pdf document in Acrobat. I just don't understand what the problem is.
----------------------------------------
Is George Lucas Kidding...
 
>>launch the pdf document in Acrobat

try using ShellExecute instead of Shell to open the PDF file

 
After a lot of testing. I don't think you can open a file and assume the associated application will open it (i.e. *.html and expect iexplore to open it). I was able to duplicate this problematice behaviour trying to open html and pdf files. However, I had no problem opening actual applications.

It would be nice if this was documented appropriately, huh?

Thanks everybody, I appreciate the help. ----------------------------------------
Is George Lucas Kidding...
 
Um - the documentation I've got for the Shell function says 'Runs an executable program', which seems pretty clear to me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top