As I said earlier I'm not an Access user. However, in the hope that this will be helpful I put together a brief example that automates Excel from an MFC dialog application. The example starts Excel, opens a macro enabled workbook and runs the macro and displays the result.
Since you mentioned that your code would run from a DLL you must ensure that the application has initialized COM for use in a Single Threaded Apartment. Typically, an MFC application (.exe.) would call AfxOleInit. A non-MFC application might call OleInitialize() or CoInitialize(Ex). The example was put together with the 64-bit version of Office 2013. Obviously you would need to adapt the example to your particular circumstances (i.e., Office version and Access instead of Excel). I hope you can use this as a guide.
In a header file -
// Imports Excel type library
#import "C:\Program Files\Microsoft Office\Office15\Excel.exe" auto_search auto_rename
In a .cpp file to do the work -
try
{
Excel::_ApplicationPtr pApp;
Excel::WorkbooksPtr pBooks;
Excel::_WorkbookPtr pBook;
CString clicked;
// Start Excel Application and get Application Object
_com_util::CheckError(pApp.CreateInstance(L"Excel.Application", NULL, CLSCTX_LOCAL_SERVER));
// Get Workbooks collection
pBooks = pApp->Workbooks;
// Open the workbook containing the macro
pBook = pBooks->Open(_bstr_t(L"C:\\Users\\RLWA32\\Documents\\Testbook2.xlsm"));
// Run the VBA function named SayHello and pass it a string
_variant_t result = pApp->Run(_variant_t("SayHello"), _variant_t("Passed Parameter"));
// Get return values from SayHello Function
clicked.Format(_T("Buttton clicked was %s"), V_I4(&result) == IDOK ? _T("OK") : _T("Cancel"));
// Close the workbook without saving
pBook->Close(_variant_t(false));
// Quit Excel
pApp->Quit();
// Dispaly SayHello return values
AfxMessageBox(clicked, MB_ICONINFORMATION);
}
catch (_com_error& ce)
{
AfxMessageBox(ce.ErrorMessage(), MB_ICONERROR);
}
Excel VBA macro -
Running the macro from MFC -
Display the result -