Showing posts with label Bat File. Show all posts
Showing posts with label Bat File. Show all posts

MS Access: Execute SSIS dtsx package from Access vba

I needed to execute dtsx package from Access VBA. After trying few attempts I found that this cannot be done directly. Instead call a bat file which again calls dtsx package or we can say SSIS package. Below is the script to run bat file through Access VBA.
RunFile "D:\test\callpackage1.bat", vbNormalFocus

To execute above script, below function has to be added as well in VBA.
Function RunFile(strFile As String, strWndStyle As String)
On Error GoTo Error_Handler

   Shell "cmd /k """ & strFile & """", strWndStyle

Error_Handler_Exit:
   On Error Resume Next
   Exit Function

Error_Handler:
   MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
   Err.Number & vbCrLf & "Error Source: RunFile" & vbCrLf & "Error Description: " & _
   Err.Description, vbCritical, "An Error has Occured!"
   Resume Error_Handler_Exit
End Function

Suppossing your package name is package1.dtsx, below script has to be mentioned inside bat file.
-@ECHO OFF
"C:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTExec.exe" /F "D:\test\package1.dtsx"
echo msgbox "FILE UPLOADED SUCESSFULLY!"