This is followup to my post on how to insert invoices into Quickbooks.
I have a custom Access database/application that is linked to some Quickbooks tables using the QODBC driver. I need a way to check to see if a record already exists in in Quickbooks table, Customer. If it does not, I need to insert it. I have seen something about a Dlookup but it is usually used with information from a form so I don't know if that will work for me. I also have used recordsets for other things, but can't get it to work in this case. I will post what I have so far, so please don't laugh....
....
Dim rsc As New ADODB.Recordset
rsc.Open "Select * from Customer", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do Until rsc.EOF
If clname <> rsc("Name") Then
DoCmd.RunSQL "Insert INTO Customer(Name,IsActive,CompanyName,BillAddressAddr1,BillAddressAddr2," & _
"BillAddressAddr3)" & _
"VALUES ('" & clname & "',1,'" & clname & "','" & cladd1 & "','" & cladd2 & "', '" & clctzp & "')"
End If
rsc.MoveNext
Loop
rsc.Close
Set rsc.ActiveConnection = Nothing
....
I know the reason it is not working is that I am comparing against all the records, and in almost every case it will not exist. Is there a way to compare against every record in the recordset?
I have a custom Access database/application that is linked to some Quickbooks tables using the QODBC driver. I need a way to check to see if a record already exists in in Quickbooks table, Customer. If it does not, I need to insert it. I have seen something about a Dlookup but it is usually used with information from a form so I don't know if that will work for me. I also have used recordsets for other things, but can't get it to work in this case. I will post what I have so far, so please don't laugh....
....
Dim rsc As New ADODB.Recordset
rsc.Open "Select * from Customer", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do Until rsc.EOF
If clname <> rsc("Name") Then
DoCmd.RunSQL "Insert INTO Customer(Name,IsActive,CompanyName,BillAddressAddr1,BillAddressAddr2," & _
"BillAddressAddr3)" & _
"VALUES ('" & clname & "',1,'" & clname & "','" & cladd1 & "','" & cladd2 & "', '" & clctzp & "')"
End If
rsc.MoveNext
Loop
rsc.Close
Set rsc.ActiveConnection = Nothing
....
I know the reason it is not working is that I am comparing against all the records, and in almost every case it will not exist. Is there a way to compare against every record in the recordset?