VBS error spotting

  • Thread starter Thread starter akivabrown
  • Start date Start date
A

akivabrown

On Error Resume Next

'custom for each broker
'Set myItemGS = oFolder.Items.Find("[subject] = ""BH GS 29062006""")
'Set myItemHSBC = oFolder.Items.Find("[subject] = ""BH HSBC
29062006""")
'Set myItemBOA = oFolder.Items.Find("[subject] = ""BH BOA 29062006""")
Set myItemWPac = oFolder.Items.Find("[subject] = ""BH WPac
29062006""")
If Err.Number = 0 then
MsgBox(MyItemWpac & setfiledate)
Else
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
Set objErrMessage = nothing
End If
'Turn back on errors
On Error GoTo 0

For some reason (maybe because i suck at programming) this is not
working, and it seems like it should. What i'm trying to do is catch
the error if the subject os not there and automate an email message to
myself . At first i tried just saying
if myItemWPac = nothing then
'send email to myself'
end if
(there was code to send the email) but i was getting an error that
myItemWPac wasn't initialized. So i went the way i had it pasted on
top. Where it shuts off the errors but then still counts the error
numbers.
If anyone can help i appreciate it greatly.

-Kevin Brown
 
You were on the right track the first time, but you forgot to create the message. Leave in the On Error Resume Next statement, then after you try to return myItemWPac, add:

if myItemWPac = nothing then
'send email to myself
Set objErrMessage = Application.CreateItem(0)
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
end if

I'm assuming you have an Application object somewhere.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I created the message earlier

Set myOlApp = createObject("outlook.application")
Set oNameSpace = myOlApp.GetNameSpace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(6)
Set objErrMessage = myOlApp.CreateItem(olMailItem)

You were on the right track the first time, but you forgot to create the message. Leave in the On Error Resume Next statement, then after you try to return myItemWPac, add:

if myItemWPac = nothing then
'send email to myself
Set objErrMessage = Application.CreateItem(0)
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
end if

I'm assuming you have an Application object somewhere.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


On Error Resume Next

'custom for each broker
'Set myItemGS = oFolder.Items.Find("[subject] = ""BH GS 29062006""")
'Set myItemHSBC = oFolder.Items.Find("[subject] = ""BH HSBC
29062006""")
'Set myItemBOA = oFolder.Items.Find("[subject] = ""BH BOA 29062006""")
Set myItemWPac = oFolder.Items.Find("[subject] = ""BH WPac
29062006""")
If Err.Number = 0 then
MsgBox(MyItemWpac & setfiledate)
Else
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
Set objErrMessage = nothing
End If
'Turn back on errors
On Error GoTo 0

For some reason (maybe because i suck at programming) this is not
working, and it seems like it should. What i'm trying to do is catch
the error if the subject os not there and automate an email message to
myself . At first i tried just saying
if myItemWPac = nothing then
'send email to myself'
end if
(there was code to send the email) but i was getting an error that
myItemWPac wasn't initialized. So i went the way i had it pasted on
top. Where it shuts off the errors but then still counts the error
numbers.
If anyone can help i appreciate it greatly.

-Kevin Brown
 
Got it working. Thanks alot Sue. You are a god. Don't forget that.



I created the message earlier

Set myOlApp = createObject("outlook.application")
Set oNameSpace = myOlApp.GetNameSpace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(6)
Set objErrMessage = myOlApp.CreateItem(olMailItem)

You were on the right track the first time, but you forgot to create the message. Leave in the On Error Resume Next statement, then after you try to return myItemWPac, add:

if myItemWPac = nothing then
'send email to myself
Set objErrMessage = Application.CreateItem(0)
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
end if

I'm assuming you have an Application object somewhere.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


On Error Resume Next

'custom for each broker
'Set myItemGS = oFolder.Items.Find("[subject] = ""BH GS 29062006""")
'Set myItemHSBC = oFolder.Items.Find("[subject] = ""BH HSBC
29062006""")
'Set myItemBOA = oFolder.Items.Find("[subject] = ""BH BOA 29062006""")
Set myItemWPac = oFolder.Items.Find("[subject] = ""BH WPac
29062006""")
If Err.Number = 0 then
MsgBox(MyItemWpac & setfiledate)
Else
objErrMessage.To = "(e-mail address removed)"
objErrMessage.Subject = "No item received from WPac"
objErrMessage.Body = "File not received. Checked at "
objErrMessage.Send
Set objErrMessage = nothing
End If
'Turn back on errors
On Error GoTo 0

For some reason (maybe because i suck at programming) this is not
working, and it seems like it should. What i'm trying to do is catch
the error if the subject os not there and automate an email message to
myself . At first i tried just saying
if myItemWPac = nothing then
'send email to myself'
end if
(there was code to send the email) but i was getting an error that
myItemWPac wasn't initialized. So i went the way i had it pasted on
top. Where it shuts off the errors but then still counts the error
numbers.
If anyone can help i appreciate it greatly.

-Kevin Brown
 
Back
Top