'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Option Explicit
Function Main()
' This step looks for the first report that is not already run. If it
' finds one then it sets the package to loop and assigns all of its
' fields in the tblScheduledReport to global variables. If none found
' It tells the package to proceed to the exit
' xxxxx 2006 05 15
Dim oConn, rst, strServer, strConn, strSQL, strReport, DTS, stpLoop, stpEnd
'Define loop and end steps
Set DTS = DTSGlobalVariables.Parent
Set stpLoop = DTS.Steps("DTSStep_DTSActiveScriptTask_8")
Set stpEnd = DTS.Steps("DTSStep_DTSActiveScriptTask_6")
'Get next report if there is one
Set oConn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
strServer = DTSGlobalVariables("strServerName").Value
strConn = "Provider=SQLOLEDB;Data Source=" & strServer & ";Initial Catalog=zDBA;Integrated Security=SSPI;"
oConn.Open strConn
strSQL = "SELECT TOP 1 * FROM tblScheduledReport WHERE schHasRun = 0 AND schIsActive = 1"
rst.Open strSQL, oConn
If rst.EOF then 'If no more, then end looping
stpLoop.DisableStep = True
stpEnd.DisableStep = False
stpEnd.ExecutionStatus = DTSStepExecStat_Waiting
Else 'If more then enter loop
stpLoop.DisableStep = False
stpEnd.DisableStep = True
stpLoop.ExecutionStatus = DTSStepExecStat_Waiting
rst.MoveFirst
DTSGlobalVariables("intCurrentID").Value = rst.Fields("schID").value
DTSGlobalVariables("strCurrentReport").Value = rst.Fields("schName").Value
DTSGlobalVariables("strCurrentFile").Value = rst.Fields("schFileName").value
DTSGlobalVariables("strCurrentSQL").Value = rst.Fields("schSQLFile").Value
DTSGlobalVariables("strCurrentExcelWorkPath") = DTSGlobalVariables("strWorkPath").Value & "\" & rst.Fields("schFileName").Value & ".xls"
DTSGlobalVariables("strUserGroup") = rst.Fields("schUserGroup").Value
DTSGlobalVariables("strCurrentTDT").Value = rst.Fields("schTDTFile").Value
End If
Set rst = Nothing
Set oConn = Nothing
Set stpLoop = Nothing
Set stpEnd = Nothing
Set DTS = Nothing
Main = DTSTaskExecResult_Success
End Function