Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

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

Forum : Trouble adding records to Invoice and other tablesSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC v5 Forum

 New Topic 
 
 Post Reply 
[1]  
 Trouble adding records to Invoice and other tables 
 Author   Message 
  Steve 
  
 Group: Members 
 Posts: 5 
 Joined: 2007-09-28 
 Profile
 Posted : 2007-09-28 07:40:10

Due to performance issues we are going away from Access Linked tables through QODBC and just writing information directly to the QODBC using ODBC functions.  I’ve gotten all the prepost checks sections working so that I can gather together the table of information that is needed to be posted.  I then am trying to use the ODBC drivers to append each line item from my local table into QB.  However, despite using a recordset structure that works in checking that data I keep getting a Missing Lexicon Element <Identifier> error message.  Could you please advise on how I should be structuring the ODBC call so I can post to the QB table?

 

Private Sub subAddTablesToQB( _

 

  varFormattedTable As String, _

 

  varQBTable As String, _

 

  varIDField)

 

Dim rs As New ADODB.Recordset

 

Dim rst As DAO.Recordset

 

Dim fld As DAO.Field

 

    Set rst = CurrentDb.OpenRecordset( _

 

      "SELECT * FROM " & varFormattedTable & _

 

      "WHERE [Select] = True;", dbOpenDynaset)

 

    If rst.RecordCount > 0 Then

‘Just want a blank recordset to append to the base table

 

        rs.Open _

 

          "SELECT “ & varQBTable & “.* FROM " & varQBTable & _

 

          "WHERE FALSE", cn

 

        rst.MoveFirst

 

        Do Until rst.EOF

 

            rs.AddNew

 

            For Each fld In rst.Fields

 

                Select Case fld.Name

 

                Case "Select", "SentToQB", varIDField

 

                Case Else

 

                    rs.Fields(fld.Name) = fld.Value

 

                End Select

 

            Next fld

 

            rs.Update

 

            rst.Edit

 

            rst!SentToQB = True

 

            rst.Update

 

            rst.MoveNext

 

        Loop

 

        rs.Close

 

        Set rs = Nothing

 

    End If

 

    rst.Close

 

End Sub

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-09-28 09:51:36

Could you please open the "Review QODBC Messages" and scroll down to the end of the file and post the last section with the actual QODBC error details.

 

  Top 
  Steve 
  
 Group: Members 
 Posts: 5 
 Joined: 2007-09-28 
 Profile
 Posted : 2007-09-29 03:41:34

***********************
IsAService: False
SQL Statement: SELECT * FROM InvoiceLine;
Invalid Table Name in Open Table. (InvoiceLine;)

2007-09-28 10:37:37 QODBC Ver:  5.00.00.104 *********************************************************************************************************************

 

  Top 
  Steve 
  
 Group: Members 
 Posts: 5 
 Joined: 2007-09-28 
 Profile
 Posted : 2007-09-29 04:03:44

I am also getting the below message.  But this doesn't make any sense as I am using the default Quickbooks Data connection which I thought I read only used the open session.  My current SQL string looks like Provider=MSDASQL.1;Extended Properties="DSN=QuickBooks Data;DFQ=.;SERVER=QODBC"

***********************
IsAService: False
Begin Session Failed. S0000 00000 [QODBC] QB Begin Session Failed. Error = 8004040a, A QuickBooks company data file is already open and it is different from the one requested.
Begin Session errors can be caused when running ASP or other system service and not setting the "Advanced" button option of either "Use DCOM Servers" or "Remote Connector"

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-09-29 06:24:20

SELECT * FROM InvoiceLine;

should only be:

SELECT * FROM InvoiceLine

but this isn't the Missing Lexicon Element error, most likely it's "WHERE [Select] = True;", which makes no sense.

 

  Top 
  Steve 
  
 Group: Members 
 Posts: 5 
 Joined: 2007-09-28 
 Profile
 Posted : 2007-09-29 06:54:35

Thanks for the reply.  It does appear that the semicolon is not part of the Lexicon error.  I reviewed the code and in testing I removed the semicolon already from the code.  I’ve restored the code using the following SQL String:

 

SELECT InvoiceLine.* FROM InvoiceLine WHERE TimeModified < {d'2001-01-01}

 

And the message I am getting from QODBC Messages is :

 

2007-09-28 13:34:19 QODBC Ver:  5.00.00.104 *********************************************************************************************************************

 

IsAService: False

 

Begin Session Failed. S0000 00000 [QODBC] QB Begin Session Failed. Error = 80040416, If QuickBooks is not running, a call to the "BeginSession" method must include the name of the QuickBooks company data file.

 

Begin Session errors can be caused when running ASP or other system service and not setting the "Advanced" button option of either "Use DCOM Servers" or "Remote Connector"

 

 

Quick books is running and this is the same connection string that I was running early in my code to test the tables and make sure these items could be posted.

 

The part of the code:

 

Set rst = CurrentDb.OpenRecordset( _

 

"SELECT * FROM " & varFormattedTable & _

 

"WHERE [Select] = True;", dbOpenDynaset)

 

 

Is where I open a recordset from my local tables to sort through what is going to be sent to QuickBooks.  There is a field called “select” (allowing the user to not send some items to QuickBooks if they don’t want to yet).  The next section is where I am getting all the problems

 

    If rst.RecordCount > 0 Then

 

        rs.Open _

 

          "SELECT " & varQBTable & ".* " & _

 

          "FROM " & varQBTable & " " & _

 

          "WHERE TimeModified < {d'2001-01-01}", cn, adOpenDynamic

 

        rst.MoveFirst

 

        Do Until rst.EOF

 

            rs.AddNew

 

Basically at this point I just want a blank recordset (called rs) that is linked to the desired QuickBooks table so that I can then add new records.  I am trying for an empty recordset so it can connect quickly and not have to sort through all the records (performance issues).  I have removed the WHERE statement and gotten the connection working, but it took a long time to load the table to memory.  Also when it got to the AddNew it gave an error that that is not available due to the client.  No messages from the QODBC message to indicate why.

 

I could either use assistance getting the filtered recordset and then adding the record, or if there is another way to add a record that would work as well.  Note this function loads four different tables.  I build a table for the invoices, deposits, payments, and credits and then post each up.  So INSERT SQL statements are not something I can build readily.  Currently I run through each field using code.  It works when I use MSSQL and just crashes when I try and run the code through QODBC.

 

        Do Until rst.EOF

 

            rs.AddNew

 

            For Each fld In rst.Fields

 

                Select Case fld.Name

 

                Case "Select", "SentToQB", varIDField

 

                Case Else

 

                    rs.Fields(fld.Name) = fld.Value

 

                End Select

 

            Next fld

 

            rs.Update

 

            rst.Edit

 

            rst!SentToQB = True

 

            rst.Update

 

            rst.MoveNext

 

        Loop

 

(Note: rst is the local database and rs is the recordset connecting to QB.)

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-09-30 08:42:44

You are using the wrong time format, TimeModified uses:  {ts '2006-07-01 HH:MM:SS.001'}, ie:

select * from InvoiceLine WHERE TimeModified > {ts '2006-07-01 00:00:00.001'}

Your connection string also needs to specifiy the QuickBooks company file you want to connect to using the DFQ=C:\Program Files\QODBC Driver for QuickBooks\sample04.qbw; parameter, see: How do I build a connection string with all the available QODBC parameters? for more information.

The company file must also auto-login in unattended mode as per: How do I setup QODBC to auto-login into QuickBooks and start it if it's not running? 

 

  Top 
  Steve 
  
 Group: Members 
 Posts: 5 
 Joined: 2007-09-28 
 Profile
 Posted : 2007-10-02 04:01:15

Still working on this problem.  You wrote:

> You are using the wrong time format, TimeModified uses:  {ts '2006-07-01

> HH:MM:SS.001'}, ie:

 

>select * from InvoiceLine WHERE TimeModified > {ts '2006-07-01 00:00:00.001'}

 

the code I posted was:

> WHERE TimeModified < {d'2001-01-01'}", cn, adOpenDynamic

 

Is there some reason I need to use a “ts” (timestamp) format instead of a “d” (date) format?

Note I ran again modified as “ts” and now am getting an “[QODBC] Invalid operand for operator: <” error.  And it gives the same error whether I use a “>” or an “=” as well.

 

You then wrote:

>Your connection string also needs to specifiy the QuickBooks company file you want to

> connect to using the DFQ=C:\Program Files\QODBC Driver for

> QuickBooks\sample04.qbw; parameter, see:...

 

As stated when I posted the QB Begin Session Failed error message, my connection string is:

> My current SQL string looks like Provider=MSDASQL.1;

> Extended Properties="DSN=QuickBooks Data;DFQ=.;SERVER=QODBC"

 

Yes QB is open when I am running the code.  Due to past training and user familiarity we actually make the user have Quickbooks open and just use the currently open company using a DFQ of “.” and the application has been given login right through QuickBooks already (connection works to run tests on tables to make sure the two application are still in sync.). 

 

I did add the “OLE DB Services=-2;” section, to kill process pooling, but still no luck.

 

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to