views:

63

answers:

1

A co-worker has inherited a Microsoft Access macro that executes a series of SQL operations against a Sybase database by calling OpenQuery on a bunch of action queries, which use linked tables over ODBC. I would like to help him convert it to an SQL script that we can execute directly against the database. And since we have quite a few macros like this, I'd like to come up with a conversion tool.

(Unless one already exists, in which case, please direct me to it.)

I expected to be able to access the details of the macro using COM interop. So far I haven't been able to find a way to get to those details. Here's what I have so far.

Imports Access = Microsoft.Office.Interop.Access
Imports System.Runtime.InteropServices

Module Module1

    Sub Main()
        Dim app As New Access.Application()
        app.OpenCurrentDatabase("c:\test.mdb")
        Dim macro As Access.AccessObject = app.CurrentProject.AllMacros("Macro1")
        'Do something with variable "macro"???'
        app.Quit(Access.AcQuitOption.acQuitSaveNone)
        Marshal.FinalReleaseComObject(app)
    End Sub

End Module

I don't think any of the members of AccessObject provide the information I need. But I can't find anything else that even mentions macros. Anybody ever done anything like this? Is there some DoCmd or SysCmd operation that will work here?

(By the way, I know that once I get the SQL I'll have the task of converting it to Sybase SQL. I'll cross that bridge when I come to it.)

+4  A: 

If it would be helpful to dump the macro definitions to text files, try something like this:

application.saveastext acMacro, "Macro1", "Macro1.txt"

You could then open the text files and read the Action and Argument statements.

HansUp
...and then get the SQL from the saved QueryDefs.
David-W-Fenton