Click here to Skip to main content
15,901,982 members
Articles / Database Development / SQL Server
Article

Execute Access 2003 Macros in SSIS Package

Rate me:
Please Sign up or sign in to vote.
2.33/5 (2 votes)
29 Dec 2006 56.4K   16   4
Execute Access 2003 Macros in SSIS Package. How to call Access Macros in SSIS Package

Note: Change the Security Level for Access Macro, otherwise whenever the SSIS package
executes, it will popup a Security Warning Message. To avoid this, follow the instructions:
Open Access -- > Tools --> Macro --> Security
Click Security and change to Low Level.

Introduction

Basically to execute Access Macros in SSIS package, we need to download Microsoft.Office.Interop.Access DLL from Office XP PIAs. The file can be downloaded from the link at the top of this article.

Using the code

  1. Extract the Microsoft.Office.Interop.Access DLL from Oxppia.exe
  2. Drag and Drop Microsoft.Office.Interop.Access DLL to Global Assembly Directory(GAC)
    • C:\WINNT\assembly for Windows 2000
    • C:\WINDOWS\assembly for Windows XP and Windows 2003
  3. Copy paste Microsoft.Office.Interop.Access to
    • C:\WINNT\Microsoft.NET\Framework\v2.0.50727 for Windows 2000
    • C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 for Windows XP and Windows 2003
  4. Add DLL reference in the Script Task
  5. Add the code given below
  6. Create a New Project in SSIS
  7. Drag and Drop the Script Task
  8. Copy Paste the code in script task editor

VB.NET
Imports Microsoft.Office.Interop.Access

Try
    Dim objAccess As New Access.Application
    objAccess.OpenCurrentDatabase("D:\TestMacro.mdb", False)    
        ' Add the Access File Path
    objAccess.DoCmd.RunMacro("Macro1") 
        ' Replace  Macro1 with the name of your macro
    objAccess.CloseCurrentDatabase()
    objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)
    objAccess = Nothing
    Catch ex As Exception
    System.Windows.Forms.MessageBox.Show(ex.ToString())
End Try

Dts.TaskResult = Dts.Results.Success

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPackage runs OK manually but not as a scheduled Job Pin
GrahamReeves00721-Apr-15 8:16
GrahamReeves00721-Apr-15 8:16 
GeneralPLEASE HELP Pin
TheHose20-Apr-11 11:47
TheHose20-Apr-11 11:47 
I like to thank you for posting a solution, but I still get an error even after addind the needed Imports statements to get around the errors. And now I'm getting a runtime error as follows:

Sysytem.Runtime.InteropServices.COMException (0x800A09C5): The Run Macro action was canceled. at Microsoft.Office.Interop.Access.DoCmd.RunMacro(Object MacroName, Object RepeatCount, Object RepeatExpression) at ST_f9c79a2b3f9e4c6b86d4210c2e6d006c.vbproj.ScriptMain.Main()

Here is the code same code just added needed imports statements:

Imports

System

Imports

System.Data

Imports

System.Math

Imports

Microsoft.SqlServer.Dts.Runtime

Imports

Microsoft.Office.Interop.Access

Imports

ADODB

Imports

dao

Imports

mscomctl

Imports

msdatasrc

Imports

stdole

Imports

Microsoft.Office.Interop

Imports

Microsoft.Office.Interop.OWC

<System.AddIn.AddIn(

"ScriptMain", Version:="1.0", Publisher:="", Description:="")> _

<System.CLSCompliantAttribute(

False)> _
Partial

Public Class ScriptMain



Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase



Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success

Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure



End Enum




' The execution engine calls this method when the task executes.


' To access the object model, use the Dts property. Connections, variables, events,


' and logging features are available as members of the Dts property as shown in the following examples.


'


' To reference a variable, call Dts.Variables("MyCaseSensitiveVariableName").Value


' To post a log entry, call Dts.Log("This is my log text", 999, Nothing)


' To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, True)


'


' To use the connections collection use something like the following:


' ConnectionManager cm = Dts.Connections.Add("OLEDB")


' cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"


'


' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.


'

' To open Help, press F1.


Public Sub Main()


'


Try


Dim objAccess As New Access.Application
objAccess.OpenCurrentDatabase(

"Z:\report_test_i3_dialer.mdb", False) ' Add the Access File Path
objAccess.DoCmd.RunMacro(

"Test_SSIS_Macro") 'Add your Macro name
objAccess.CloseCurrentDatabase()

objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

objAccess =

Nothing


Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString())



End Try


' Add your code here


'
Dts.TaskResult = ScriptResults.Success



End Sub
End

Class

Confused | :confused:
GeneralPlease help... Pin
André Stroebel27-Jun-07 0:01
André Stroebel27-Jun-07 0:01 
GeneralRe: Please help... Pin
senenami24-Jul-07 11:56
senenami24-Jul-07 11:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.