Yes, it is definitely possible. There are several ways to do it. Here's a quick overview of what will probably be the easiest way:
1. First search for "*.olb" files on your system. On my PC, which has Access 97, the appropriate file is c:\msoffice\office\msacc8.olb. The file name will be different if you're using a different Access version.
2. Create a wrapper class for the type library. To do this, start Class Wizard and go to the Class Info tab. Pick Add Class and then "from a type library". Select the appropriate .olb file.
3. Use the functions provided by the wrapper classes. For instance, you might produce some code like this:
//Start a new instance of Microsoft Access
_Application oAccessApp; if ( !oAccessApp.CreateDispatch( "Access.Application", NULL ) )
{
AfxMessageBox( "Failed to run Access." );
} else
{
oAccessApp.OpenCurrentDatabase( "c:\\my database.mdb", FALSE );
// do other stuff here, and then maybe some cleanup???
}
I didn't even try to compile this, though, so... no guarantees!
MSDN has a great deal of documentation on automating Access and the other Office apps. For some excellent MSDN links, please see this forum's FAQ on automating Office.
One final note: The MSDN documentation I have found will give you tons of info on how to automate an app, but I have been unable to locate much info on the individual functions (such as the OpenReport fxn in the above code) provided by the wrapper classes. The best source of info I have found on them (I'm probably missing something!) is to go into Access' Module Editor, type the function name, hit F1, and hope that you get help on the equivalent VBA function.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.