From: Naushad on
Hi All,

I have written a VBA code to open a word file in iexplore by the shell
command. If the file is not found a message is displayed and the
internet explorer is opened.

I want to display the custom message and don't want to open the
iexplore. My code are as follows

Private Sub cmdReport_Click()
On Error GoTo Err_cmdReport_Click

Dim VarPath As String
Dim VarReport As String
Dim varRepDate As Variant
Dim VarCon As String

VarPath = "C:\Documents and Settings\nhaider\Desktop\"
varRepDate = Format$(Me.ReportDate, "dd\-mm\-yy")
VarReport = varRepDate & "@" & Me.Project__ & ".doc"
VarCon = VarPath & VarReport

Shell "C:\Program Files\Internet Explorer\iexplore.exe " &
VarCon, vbMaximizedFocus

Me.ReportDate.SetFocus

Exit_cmdReport_Click:
Exit Sub

Err_cmdReport_Click:
MsgBox Err.Description
Resume Exit_cmdReport_Click

End Sub

Please help me to solve this problem.

Thanks in advance

Naushad
From: Terry Kreft on
Check for the existence of the file yourself and display your own message if
it's not found.

Private Sub cmdReport_Click()
On Error GoTo Err_cmdReport_Click

Dim VarPath As String
Dim VarReport As String
Dim varRepDate As Variant
Dim VarCon As String

VarPath = "C:\Documents and Settings\nhaider\Desktop\"
varRepDate = Format$(Me.ReportDate, "dd\-mm\-yy")
VarReport = varRepDate & "@" & Me.Project__ & ".doc"
VarCon = VarPath & VarReport

if len(dir(VarCon) > 0 Then
Shell "C:\Program Files\Internet Explorer\iexplore.exe " &
VarCon, vbMaximizedFocus
else
Msgbox "Can't find the file '" & VarCon & "'"
End if
Me.ReportDate.SetFocus

Exit_cmdReport_Click:
Exit Sub

Err_cmdReport_Click:
MsgBox Err.Description
Resume Exit_cmdReport_Click

End Sub


--
Terry Kreft


"Naushad" <nhaider(a)kockw.com> wrote in message
news:9e7b29b2-1c17-41a2-ae78-9fc7b2978a7d(a)v25g2000yqk.googlegroups.com...
> Hi All,
>
> I have written a VBA code to open a word file in iexplore by the shell
> command. If the file is not found a message is displayed and the
> internet explorer is opened.
>
> I want to display the custom message and don't want to open the
> iexplore. My code are as follows
>
> Private Sub cmdReport_Click()
> On Error GoTo Err_cmdReport_Click
>
> Dim VarPath As String
> Dim VarReport As String
> Dim varRepDate As Variant
> Dim VarCon As String
>
> VarPath = "C:\Documents and Settings\nhaider\Desktop\"
> varRepDate = Format$(Me.ReportDate, "dd\-mm\-yy")
> VarReport = varRepDate & "@" & Me.Project__ & ".doc"
> VarCon = VarPath & VarReport
>
> Shell "C:\Program Files\Internet Explorer\iexplore.exe " &
> VarCon, vbMaximizedFocus
>
> Me.ReportDate.SetFocus
>
> Exit_cmdReport_Click:
> Exit Sub
>
> Err_cmdReport_Click:
> MsgBox Err.Description
> Resume Exit_cmdReport_Click
>
> End Sub
>
> Please help me to solve this problem.
>
> Thanks in advance
>
> Naushad