Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Logic help needed

Author  Topic 

sardinka
Posting Yak Master

142 Posts

Posted - 2006-11-17 : 09:11:06
What am I doing wrong? I am looping though global variables and I have another task where I am sending emails. What I want to do is any of the files were rename send email. but it is not working why?
I have on sucess send email.
thanks
Function Main()
' Convert current date & time
Dim strResult,strDay,strMonth,strYear
strYear=Right( Year(Now()) , 2 )
If Len (Month(Now()))=1 Then
strMonth="0"& Month(Now())
Else
strMonth=Month(Now())
End if
if Len(Day(Now() )) = 1 then
strDay="0" & Day(Now())
Else
strDay=Day(Now() )
end if
strResult =strMonth & strDay& strYear

' Look for Files
Dim sPath, gVar,oPackage,sDestinationFile,oFSO
Set oPackage = DTSGlobalVariables.Parent
sPath="C:\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
'Loop through all the Global variables to get the file names
For Each gVar In oPackage.GlobalVariables
If Not oFSO.FileExists( sPath & gVar.Value) Then
Main=DTSTaskExecResult_Failure
Else
' Rename the file
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.MoveFile sPath & gVar.Value, sPath & gVar.Value & "_" & strResult & Left( (Replace((FormatDateTime( Now() ,3)) , ":" , "" ) ),6)
Main=DTSTaskExecResult_Success

End If

Next
Set oFile = Nothing
Set oFSO = Nothing

End Function

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-11-22 : 08:42:44
You're setting the outcome of the task for each iteration of your loop - that ain't right! I'm assuming that it is only when the last iteration is a file that exists that your task will have a successful outcome, allowing the proceeding task to execute.

Mark
Go to Top of Page
   

- Advertisement -