Knowledgebase: Microsoft Products
[QODBC-Desktop] QODBC and Microsoft Visual Basic and ADO
Posted by Juliet (QODBC Support) on 12 February 2010 02:11 AM

How to use ADO and Visual Basic with QODBC

Setup QODBC to work with ADO

     Note: QODBC can be accessed from ADO. ADO can be used in Visual Basic (VB), Access, VBScript, ASP, C++, VB.NET, C#, and other languages that support COM components.

Connection String
     The most challenging part of using QODBC in programming is the connection string. The simplest form includes a reference to a DSN. A system DSN called QuickBooks Data is automatically created when QODBC is installed. QuickBooks Data will be used in all examples but can be substituted for any different DSN name you create.

     Normally ADO pools connections. QODBC does NOT support connection pooling. It is recommended to tell ADO not to do connection pooling on any QODBC connection. This is done with OLE DB Services= -2.

Other options available on the connection string:
bullet DFQ = Path to company file or. (dot) to indicate the currently open company file.

bullet OpenMode = F (Follow Company), M (Multi-user), S (Single-user).

bullet DeveloperCode = This is for users of the QODBC v5 OEM version only. It is required to connect to the OEM licensing model. The Code is given to you when you purchase a QODBC v5OEM licensing pack.

bullet ColumnNameLen = This is a number that specifies the maximum length a column name can be. Using this is required in some development environments. Its use will make the returned column names not match the normally defined schema.

Example of simple DSN
sConnectString = "DSN=QuickBooks Data;OLE DB Services=-2;"

Example of a DSNless connection string
sConnectString = "Driver={QODBC Driver for QuickBooks};DFQ=C:\Program Files\QODBC Driver for QuickBooks\sample04.qbw;OpenMode=M;OLE DB Services=-2;"

Example using current ADO syntax
sConnectString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QuickBooks Data;OLE DB Services=-2;"

Standard syntax
"DRIVER={QODBC Driver for QuickBooks};SERVER=QODBC;DFQ=.;OLE DB Services=-2;OptimizerOn=No;"

Instructions for Parameters in Standard Syntax

DFQ (./[path to .qbw file]) : . means the current company file is open in QuickBooks
OLE DB Services = -2
OptimizerOn : Yes/No
OpenMode : F/S/M <=> Follow company setting/Single-User/Multi-user
UseCaseSensitiveRefNumber : Yes/No

[Note: For QuickBooks Online Edition (QBOE), these additional parameters can also be used]
IBizOEConnection: Yes/No
IBizOETicketGUID: (GUID from web login)
IBizOEPromptForLogin: Yes/No

 

 

Query Data VBS Example

'*****************************************
Const adOpenStatic = 3
Const adLockOptimistic = 3

Dim oConnection
Dim oRecordset
Dim sMsg
Dim sConnectString
Dim sSQL

sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "SELECT Name FROM Employee"
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")

oConnection.Open sConnectString
oRecordset.Open sSQL, oConnection, adOpenStatic, adLockOptimistic
sMsg = "**********************" & Chr(10)
Do While (not oRecordset.EOF)
sMsg = sMsg & oRecordSet.Fields("Name") & Chr(10)
oRecordset.MoveNext
Loop
sMsg = sMsg & "**********************" & Chr(10)
MsgBox sMsg

oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection = Nothing
'*****************************************

 

VBA

Save your VBA file as QODBC Query Data.vbs, To execute the VBS file, Double Click on the file.

 

VBA

 

Visual Basic 6 Example

Note: Requires project reference to Microsoft ActiveX Data Objects 2. x Library

'*****************************************
Dim oConnection As ADODB.Connection
Dim oRecordset As ADODB.Recordset
Dim sMsg As String
Dim sConnectString As String
Dim sSQL As String

sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "SELECT Name FROM Employee"
Set oConnection = New ADODB.Connection
Set oRecordset = New ADODB.Recordset

oConnection.Open sConnectString
oRecordset.Open sSQL, oConnection, adOpenStatic, adLockOptimistic
sMsg = "**********************" & Chr(10)
Do While (Not oRecordset.EOF)
sMsg = sMsg & oRecordset.Fields("Name") & Chr(10)
oRecordset.MoveNext
Loop
sMsg = sMsg & "**********************" & Chr(10)
MsgBox sMsg

oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection = Nothing
'*****************************************

vb6

 

Sp_report Query Data VBS Example

Note: For QuickBooks reports, use sp_report like any other SELECT statement. For example, save the following example as sp_report.vbs to a file.

'*****************************************
Const adOpenStatic = 3
Const adLockOptimistic = 3

Dim oConnection
Dim oRecordset
Dim sMsg
Dim sConnectString
Dim sSQL

sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "sp_report CustomerBalanceSummary show Text, Label, Amount_1 parameters DateMacro = 'ThisMonthToDate', SummarizeColumnsBy = 'TotalOnly'"

Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")

oConnection.Open sConnectString
oRecordset.Open sSQL, oConnection, adOpenStatic, adLockOptimistic
sMsg = "**********************" & Chr(10)
Do While (not oRecordset.EOF)
sMsg = sMsg & oRecordSet.Fields("Text")
sMsg = sMsg & " " & oRecordSet.Fields("Label")
sMsg = sMsg & " $" & oRecordSet.Fields("Amount_1") & Chr(10)
oRecordset.MoveNext
Loop
sMsg = sMsg & "**********************" & Chr(10)
MsgBox sMsg

oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection = Nothing
'*****************************************

Double-click on it using Windows Explorer, and you will get your Customer Balances:

Keywords: vbs adodb connection 64-bit vbs

 

(271 vote(s))
Helpful
Not helpful

Comments (6)
Phil Howes
26 April 2013 01:12 PM
I am getting an error meesage with the first and third example on this line:

oConnection.Open sConnectString

the message is:
The Specified DSN contains a mismatch between the Driver and Application
Code 80004005

Any suggestions what I am doing wrong?
thanks very much
Rajendra Dewani
21 September 2013 08:29 AM
The specified DSN contains an architecture mismatch between the Driver and Application
Refer : http://support.flexquarters.com/esupport/index.php?/Default/Knowledgebase/Article/View/2439/0/qodbc-reports-architecture-mismatch-problem-when-connecting
Garry
18 September 2015 03:26 AM
Is there a way to run a vb script without Reckon Accounts running on the background?
Jack
18 September 2015 11:39 AM
Hi Gary,

You can't fetch QuickBooks data without QuickBooks is running either in background/foreground. QuickBooks needs to be in running mode to access data using QODBC.
Helen Feddema
15 October 2017 04:08 PM
I wrote a procedure to update the QuickBooks Customer table from an Access record. The connection string seems to be OK (no errors when setting it), and the record appears to be editable, but the code fails on the Update line with an error "Query-based update failed because the row to update cannot be found". The row is correct -- I check that with a Debug.Print statement. How can I fix this error?

Also, can you post sample code for updating QuickBooks from Access?
Jack
16 October 2017 07:07 AM
Hi Helen,

Please refer below mentioned article for sample VBA code, You can refer below link & can make changes in the code as per your requirement:
http://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2571

Please refer below mentioned link for How to Import data to QuickBooks through CSV using QODBC:
http://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2753

If you are still facing the issue, Please raise a support ticket to the QODBC Technical Support department from below mentioned link & provide requested information:
http://support.flexquarters.com/esupport/index.php?/Tickets/Submit

We may need the following information, Please attach below listed files when replying to the ticket.
1) Screenshot of QODBC Setup Screen -- > About
2) Screenshot of the issue you’re facing.
Share Entire Log Files as an attachment in text format from
3) QODBC Setup Screen -- > Messages -- > Review QODBC Messages
4) QODBC Setup Screen -- > Messages -- > Review SDK Messages
Refer: How to take screenshot: www.qodbc.com/links/screenshot.htm

Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).