Conditional Email If Table values not null -
07-06-2006
, 08:24 PM
Hi
I have been cracking my skull on sending a conditional email only if
values in an Excel spreadsheet are present. I have already queried the
database to export (via DTS) only interested values to the spreadsheet.
I need help in getting the syntax and placement of the IF statements
correct.
Also, if there is some way to only check whether if the query is not
null instead of the Excel spreadsheet, that would be fantastic as well.
Thanks!
************************************************** ********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
'References to Excel
dim xl_app
dim xl_Spreadsheet
SET xl_app = CREATEOBJECT("Excel.Application")
'SET xl_app = GetObject("\\mongoReport.xls")
SET xl_spreadsheet = xl_app.Workbooks.Open("mongoReport.xls")
'Run the macro
xl_app.Run("transform_macro")
xl_spreadsheet.Save
xl_spreadsheet.Close
xl_app.Quit
set xl_app = Nothing
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "qarelay1"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
If xl_spreadsheet.table.value(null) --------------------> Is this the
correct placement and syntax??
With cdoMessage
Set .Configuration = cdoConfig
.From = "repor... (AT) acme (DOT) com"
.To = "mongomadn... (AT) acme (DOT) com"
.Subject = "Automated Report For Today"
.TextBody = "We have found significant errors for your
correction."
.AddAttachment ( "\\mongoReport.xls")
.Send
End With
else ----------------------->Is this the correct placement and syntax??
With cdoMessage
Set .Configuration = cdoConfig
.From = "repor... (AT) acme (DOT) com"
.To = "mongomadn... (AT) acme (DOT) com"
.Subject = "Automated Report For Today"
.TextBody = "There are no errors for correction today."
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Main = DTSTaskExecResult_Success
End Function |