Buy Support
Incidents |
If you can't find your answer
in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us
private or confidential information: |
Click Here
|
If you can't
login and post questions or you are having trouble viewing forum posts:
Click Here
|
Callback
Support |
If you live in USA, UK, Canada, Australia or New
Zealand, you can leave us details on your question and request us to call you back and discuss
them with you personally (charges apply). |
Click Here
|
Buy Support
Incidents |
If you can't find your answer
in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us
private or confidential information: |
Click Here
|
|
How do I use ADO and Visual Basic? |
Author |
Message |
Tom |
|
Group | : Administrator |
Posts | : 5510 |
Joined | : 2006-02-17 |
|
Profile |
|
Posted : 2006-03-01 19:54:53 |
Setting up QODBC to work with ADO QODBC can be accessed from ADO. ADO can be used in Visual Basic (VB), Access, VBScripts, ASP, C++, VB.NET, C# and any other language that supports COM components. Connection String The most difficult 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 with any different DSN name you create. Normally ADO pools connections. QODBC does not support connection pooling. It is recommended to tell ADO to not do connection pooling on any QODBC connection. This is done with OLE DB Services=-2. Other options available on the connection string:
|
DFQ = Path to company file or . (dot) to indicate currently open company file. |
|
OpenMode = F (Follow Company), M (Multi-user), S (Single-user). |
|
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 v5 OEM licensing pack. |
|
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 normal 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;"
DFQ (./[path to .qbw file]) where . means current company file open in QuickBooks. OLE DB Services=-2; OptimizerOn (Yes/No) OpenMode (F/S/M) Follow company setting/Single-User/Multi-user UseCaseSensitiveRefNumber (Yes/No)
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 '*****************************************
Visual Basic 6 Example 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 '*****************************************
|
|
|
|
Tom |
|
Group | : Administrator |
Posts | : 5510 |
Joined | : 2006-02-17 |
|
Profile |
|
Posted : 2007-02-02 22:14:16 |
For QuickBooks reports, just 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:
|
|
|
|
|