Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Access using COM via C++

Status
Not open for further replies.

newora

Programmer
Aug 19, 2003
133
GB
Hi There All,

I wonder if someone could please help me with a problem that I am having trying to run an Access 2000 module via a small C++ DLL, using COM.

I am trying to use the Run method of the Access 2000 type library, to run the appropriate module, which has been developed under Access 2000 using VB.

The problem that I am having is to do with the fact that the Run method can accept up to 30 parameters, but I am only passing 20 parameters and so when I compile up, I get an error saying that the function does not take 20 parameters. I have modified the function prototype in msacc9.cpp and the hedare file for just 2 parameters, as a test and it compiles OK. However when I run it I noe get a bad variable type error from the access DB when I try to run the module. I know thatthe run method can take any number of parameters, so do I need to use funtion overloading to declare the Run method with only 20 parameters, or am I missing something.

I am passing the 2 arguements (first 1 a float and second 1 a string) using a tagvariant struct.

Code follows :-

char retval = ' ';
_Application openaccess;
tagVARIANT arg1,arg2;
int res;

arg1.dblVal = 12.34;
arg2.pcVal = "Test";

// initialise COM

res = CoInitializeEx(0, COINIT_MULTITHREADED);

if(res)
{
AfxMessageBox ("Coinitialise Error");
return ('1');
}

// Start Access and get Application object.
if(openaccess.CreateDispatch("Access.Application") == 0)
{
AfxMessageBox("Couldn't start Access and get Application object.");
return ('1');
}

openaccess.SetVisible(FALSE);
openaccess.OpenCurrentDatabase("c:\data.mdb",FALSE)
//Error displayed after this next line is traced into
openaccess.Run ("sp_update",&arg1,&arg2);
openaccess.CloseCurrentDatabase();

openaccess = NULL;


Thanks a lot for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top