Question

I have a small C# console program that retrieves an item list from quickbooks, and I am trying to figure out how to expose that data to Microsoft Access. It is in XML format.

I want to retrieve the data in real-time, since it only takes about a second to get the data, whenever Access calls for it. I am using Access 2003 and VS 2010.

If there is a way to do this with VBA that would work fine as well. I can get the XML data using VBA already, but I don't know how to go from there.

Here is the code I use in C#:

public string DoQBQuery(XmlDocument doc)
{
    bool sessionBegun = false;
    bool connectionOpen = false;
    RequestProcessor2 rp = null;
    string ticket = "";
    try
    {
        //Create the Request Processor object
        rp = new RequestProcessor2();

        //Connect to QuickBooks and begin a session
        rp.OpenConnection2("", "QB Transaction Item Retriever", QBXMLRPConnectionType.localQBD);
        connectionOpen = true;
        ticket = rp.BeginSession("", QBFileMode.qbFileOpenDoNotCare);
        sessionBegun = true;

        //Send the request and get the response from QuickBooks
        string responseStr = rp.ProcessRequest(ticket, doc.OuterXml);

        //End the session and close the connection to QuickBooks
        rp.EndSession(ticket);
        sessionBegun = false;
        rp.CloseConnection();
        connectionOpen = false;

        return responseStr;

    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message, "Error");
        if (sessionBegun)
            rp.EndSession(ticket);

        if (connectionOpen)
            rp.CloseConnection();

        throw;
    }
}
Was it helpful?

Solution

"I am trying to figure out how to expose that data to Microsoft Access. It is in XML format" I've never tried this before, but I think this is possible by putting the c# classes that accomplish what you discussed in a dll and calling from Access. Here is a post from this site about that.

A Simple C# DLL - how do I call it from Excel, Access, VBA, VB6?

P.S. Given I've never tried this before, I would have put this in the comment section of your original post, but I'm new to this site and am unable to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top