Accessing a VBA module from VB or C#. Maybe a better solution?

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

This does sound like a bit of a weird thing to ask so I will state my
question and then further down explain why I am trying to do it. So
if you have the answer then reply! Or if you understand what I am
trying to do and can suggest a better solution then reply also!

Question
--------
I want to run a VBA code module from either VB/VB.NET/C#. How can I
go about calling the call module?

Why
---

I have an MS Access project that is hooked up with SQL-MSDE. I have
developed a complex and nice looking report. What I want to do is let
my work colleges view it over the internal intranet. The Data Access
Pages doesn't seem to work - Access throws a fit over the calulated
fields. In Access though you can use the ExportXML feature and it
creates the XML files that can be viewed in any web browser. So I
have written a code module that does this in the Access project. I
then want to run this and the XMl files will get updated. Simple
request I thought..

Any help, as always, greatly appreciated.

cheers
Mike
 
You can use automation to achieve this:

Dim acc As Object

Set acc = CreateObject("Access.Application")

acc.OpenCurrentDatabase "PathToYourDB"
acc.DoCmd.OpenModule "ModuleName", "ProcedureName"

Set acc = Nothing
 
Scott's concept is a good one, and it should make it clear that Access must
be installed on the machine where this code is running.
The code he supplies is in VB6.0; the same thing can be done in .NET
languages, but the syntax is a little different.

The one problem I see is in this line:
acc.DoCmd.OpenModule "ModuleName", "ProcedureName"

This will open the module for editing, which is not, I believe, what is
desired.
Make sure the procedure you want to call (I'll call it MyProcedure) is
declared as Public.
Then you can call it like this:
acc.MyProcedure

However, this is still a kludgy way to display a report on an Internet page.
You might want to look into Front Page - or since you mention .NET, try
ASP.NET - it's incredibly powerful!

HTH
- Turtle
 
Thanks for that - I will try it tonight.

Scott McDaniel said:
You can use automation to achieve this:

Dim acc As Object

Set acc = CreateObject("Access.Application")

acc.OpenCurrentDatabase "PathToYourDB"
acc.DoCmd.OpenModule "ModuleName", "ProcedureName"

Set acc = Nothing
 
Back
Top