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!

IF Statement for Shell Command? 1

Status
Not open for further replies.

keiem

Technical User
Aug 1, 2001
27
US
I have the following code, which calls the Common File Dialog Box, for the selection of a file. The function returns a filename that is then passed to a CreateObject script I found, and opens the file using Adobe Acrobat.

The problem is that if the Common File Dialog Box is cancelled, or no file is selected, Adobe Acrobat still opens...but with no file. The code works fine, but the application opening on a cancelled action is annoying.

Does anyone know of a simple way to halt the operation if a file isn't selected?

Thanks.

_______________________________

Private Sub Command59_Click()
Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "*")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an file...", _
Flags:=ahtOFN_HIDEREADONLY)

If IsNull(strInputFileName) Then
Exit Sub

Else: CreateObject("WScript.Shell").Run "acrobat """ & strInputFileName & """"
End If

End Sub
 
I would guess that the cancel button returns "" rather than null.

So:

If strInputFileName="" Then
exit sub
 
That was it. Knew I was missing something. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top