Solved

Running a macro in Access

Posted on 2003-12-09
9
229 Views
Last Modified: 2013-11-20
I have to run a macro in Access (don't ask me why).  How can I do this through one of the MFC database classes?
0
Comment
Question by:mnashadka
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9906774
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9906791
Oops, it's not Access. Sorry.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9910989
No.  You can only get at the tables and queries with the MFC Database classes.
You may be able to do it with automation - but I haven't tried this (also do you really mean a macro or a piece of code in a module).
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Author Comment

by:mnashadka
ID: 9912646
It could either be a macro or a sub.  I figured that macros would be easier.  I tried to #import "path\msacc9.olb" to get to the automation, but it gave me some errors about a Property class not being defined.  I was also #importing the MSO9.dll and the VBE6EXT.olb (I think those were the extensions, and I tried it with both no_namespace and using namespace after the import, but I couldn't get past that error.
0
 
LVL 5

Expert Comment

by:Nass89
ID: 10189866
Hi,
You could use DDE(Dynamic Data Exchange) to run a macro in Access. I did it using National Instruments Labview, but I didn't it using MFC. I think it is possible to run macro with MFC too.

Good Luck!
0
 
LVL 8

Author Comment

by:mnashadka
ID: 10201077
Nass89, could you explain how you did it?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 10201250
This was in another question.  It looks like it is what you require.  (What error do you get with the #import ?)

COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
     
     MSAccess::_Application oApp;
    oApp.CreateDispatch("Access.Application");
     MSAccess::DoCmd oDoCmd = oApp.GetDoCmd();
     oApp.OpenCurrentDatabase("C:\\Documents and Settings\\Administrator\\Desktop\\ASSISTENT BASE\\AS_DB1.mdb", FALSE,"macro1");
     
     oApp.SetVisible(true);

     
     MSAccess::_CurrentProject oProj = oApp.GetCurrentProject();
    MSAccess::AllObjects oObjs = oProj.GetAllModules();

    CString sModName, sProcName, sItem;
   
          //Module must be open:
         
     oDoCmd.RunMacro(COleVariant("macro1"),vOpt,COleVariant(sModName));
    oDoCmd.Maximize();
0
 
LVL 5

Expert Comment

by:Nass89
ID: 10206982
Hi,
As I wrote, I did it with National Instruments LABVIEW. If you can use DDE, the procedure is the same.
First open a DDE connection to your databse file. Second run a command using Macro name, and finally close the connection.
Can you use DDE ? MSDN hase many article about it.

Good Luck!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 132
sum13 challenge 24 123
java ^ examples 8 69
changeXy challenge 13 89
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question