Quantcast
Channel: FLEXquarters.com Limited
Viewing all articles
Browse latest Browse all 313

How to Import data to QuickBooks through CSV using QODBC

$
0
0

How to Import data to QuickBooks through CSV using QODBC

Note: QODBC does not support direct import, But you can write VBA code which reads a CSV / Excel file & generates insert statements.

Please refer Using QuickBooks Data with VBA

In this tutorial, we are showing sample VBA script which is inserting Customer & Invoice.

1. Importing Customer to QuickBooks through CSV file using QODBC

We have Customer CSV file which has Customer Name,CompanyName,Phone & Email fields.

We will import this fields to QuickBooks using VBA. You can see below records from Customer CSV file.

.

 

Please refer below sample VBA code for Importing Customer to QuickBooks through CSV file using QODBC.

By clicking on "Add Customer" button, Customer list in CSV file will be Imported into QuickBooks using QODBC.

 

Please Note: You need to change CSV file location & VBA script according to your CSV file location & file data.

Please refer below code which is use in this example:

Import Customer:

 

Option Compare Database

Public Sub exampleCsvImportCustomer()

Dim oConnection As New ADODB.Connection
Dim sConnectString
Dim MyArray As Variant
Dim fso As Variant
Dim objStream As Variant
Dim objFile As Variant
Dim sSQL As String
Dim sMsg
Dim rs
Dim i As Integer
i = 0
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "SELECT * FROM customer"

Set rs = New ADODB.Recordset
oConnection.Open (sConnectString)
rs.Open sSQL, oConnection, adOpenDynamic, adLockOptimistic

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists("C:\Input\Customer.csv") Then
Set objStream = fso.OpenTextFile("C:\Input\Customer.csv", 1, False, 0)
End If

Do While Not objStream.AtEndOfStream
strLine = objStream.ReadLine
ReDim MyArray(0)
MyArray = Split(strLine, ",")
rs.AddNew
rs("Name") = MyArray(0)
rs("CompanyName") = MyArray(1)
rs("Phone") = MyArray(2)
rs("Email") = MyArray(3)
rs.Update
i = i + 1

Loop

sMsg = sMsg & "Customer Added!!!"
MsgBox sMsg

End Sub

2. Importing Invoice to QuickBooks through CSV file using QODBC

We have Invoice CSV file which have CustomerRefListID, RefNumber, InvoiceLineItemRefListID, InvoiceLineDesc, InvoiceLineRate, InvoiceLineQuantity, InvoiceLineSalesTaxCodeRefListID & FQSaveToCache fields.

We will import this fields to QuickBooks using VBA. In this example, we are creating two Invoice each having 3 InvoiceLine. You can see below records from Invoice CSV file.

Please refer below sample VBA code for Importing Invoice to QuickBooks through CSV file using QODBC.

By clicking on "Add Invoice" button, Invoice list in CSV file will be Imported into QuickBooks using QODBC.

 

Please Note: You need to change CSV file location & VBA script according to your CSV file location & file data.

Please refer below code which is use in this example:

Import Invoice:

 

Option Compare Database

Public Sub exampleCsvImportInvoice()
Dim oConnection As New ADODB.Connection
Dim sConnectString
Dim MyArray As Variant
Dim fso As Variant
Dim objStream As Variant
Dim objFile As Variant
Dim sSQL As String
Dim rs
Dim sMsg
Dim i As Integer
i = 0

sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "SELECT * FROM InvoiceLine"

Set rs = New ADODB.Recordset
oConnection.Open (sConnectString)
rs.Open sSQL, oConnection, adOpenDynamic, adLockOptimistic

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists("C:\Input\Invoice.csv") Then
Set objStream = fso.OpenTextFile("C:\Input\Invoice.csv", 1, False, 0)
End If

Do While Not objStream.AtEndOfStream
strLine = objStream.ReadLine
ReDim MyArray(0)
MyArray = Split(strLine, ",")
rs.AddNew
rs("CustomerRefListID") = MyArray(0)
rs("RefNumber") = MyArray(1)
rs("InvoiceLineItemRefListID") = MyArray(2)
rs("InvoiceLineDesc") = MyArray(3)
rs("InvoiceLineRate") = MyArray(4)
rs("InvoiceLineQuantity") = MyArray(5)
rs("InvoiceLineSalesTaxCodeRefListID") = MyArray(6)
rs("FQSaveToCache") = MyArray(7)
rs.Update
i = i + 1

Loop

sMsg = sMsg & "Invoice Added!!!"
MsgBox sMsg

End Sub

 

Download Sample


Viewing all articles
Browse latest Browse all 313

Trending Articles