Jerms3033
Jerms3033

Reputation: 101

Modfying Invoice Line Items in Quickbooks using QBFC and VBA

I'm trying to modify line items in an existing Quickbooks Invoice using vba code. I keep getting the following error message:

Invoice Mod
ORInvoiceLineModList:
element(2) - InvoiceLineMod:
TxnLineID: required field is missing
End of InvoiceLineMod
End of ORInvoiceLineModList
End of InvoiceMod

Here's my vba code for building the request:

Set InvoiceModReq = msreq.AppendInvoiceModRq
With rsHDR
    InvoiceModReq.TxnID.SetValue Nz(rsHDR![TxnNo], "")

    InvoiceModReq.EditSequence.SetValue Nz(rsHDR![QBEditSequence], "")

    InvoiceModReq.CustomerRef.ListID.SetValue Nz(rsHDR![QBListID], "")

    If Nz(rsHDR![AcctgShipDate], "") <> "" Then
        InvoiceModReq.TxnDate.SetValue rsHDR![AcctgShipDate]
    End If

    If Nz(rsHDR![ActualShipDate], "") <> "" Then
        InvoiceModReq.ShipDate.SetValue Nz(rsHDR![ActualShipDate], "")
    End If

    InvoiceModReq.RefNumber.SetValue Nz(rsHDR![InvNo], "")
    InvoiceModReq.PONumber.SetValue Nz(rsHDR![PONo], "")

    InvoiceModReq.TermsRef.ListID.SetValue Nz(rsHDR![ptQBListID], "")

    InvoiceModReq.SalesRepRef.ListID.SetValue Nz(rsHDR![raQBListID], "")

    InvoiceModReq.ShipMethodRef.ListID.SetValue Nz(rsHDR![svQBListID], "")

    InvoiceModReq.FOB.SetValue Nz(rsHDR!FOB, "")

    InvoiceModReq.ClassRef.ListID.SetValue Nz(rsHDR![clQBListID], "")

    'Line Items
            If Nz(rsHDR![SealSales], 0) <> 0 Then
                Set InvoiceLineModReq = InvoiceModReq.ORInvoiceLineModList.Append()

                InvoiceLineModReq.InvoiceLineMod.TxnLineID.SetValue "1001"

                Set rsLineItems = GetSalesOrder_LineItem_RecordSet(InvID, "Seal Strip")

                If Nz(rsLineItems!QBListID) <> "" Then
                    InvoiceLineModReq.InvoiceLineMod.ItemRef.ListID.SetValue Nz(rsLineItems!QBListID)
                End If
                InvoiceLineModReq.InvoiceLineMod.Quantity.SetValue Nz(rsLineItems!Qty, 0)
                InvoiceLineModReq.InvoiceLineMod.Amount.SetValue rsHDR![SealSales]
                rsLineItems.Close
            End If

            If Nz(rsHDR![DeckleSales], 0) <> 0 Then
                Set InvoiceLineModReq = InvoiceModReq.ORInvoiceLineModList.Append()

                 InvoiceLineModReq.InvoiceLineMod.TxnLineID.SetValue "1002"

                Set rsLineItems = GetSalesOrder_LineItem_RecordSet(InvID, "Deckle")

                If Nz(rsLineItems!QBListID, "") <> "" Then
                    InvoiceLineModReq.InvoiceLineMod.ItemRef.ListID.SetValue Nz(rsLineItems!QBListID)
                End If
                InvoiceLineModReq.InvoiceLineMod.Quantity.SetValue Nz(rsLineItems!Qty, 0)
                InvoiceLineModReq.InvoiceLineMod.Amount.SetValue rsHDR![DeckleSales]
                rsLineItems.Close
            End If

I know I need to designate the TxnLineID and EditSequence, but I have no idea how to capture that information.

Upvotes: 0

Views: 784

Answers (1)

Hpjchobbes
Hpjchobbes

Reputation: 1319

Within the returned InvoiceRet object that you use to get the TxnID and TxnEditSequence, there will be a ORInvoiceLineRet. This is a list of all the line items on the invoice. It's an OR object as the line can be an InvoiceLineRet or InvoiceLineGroupRet object (Group lines are comprised of multiple InvoiceLines and/or multiple GroupLines).

Each of these lines will have a TxnLineID value that you need to supply for the line that you are modifying. If you are trying to add a new line after all of the invoice lines, then you use "-1" as your TxnLineID value.

If you are not making any changes to the line item table of a transaction, do not include references to any of the lines in the transaction Modify request. The line item table will be retained as is, and ignoring the table completely will speed up processing of the request.

Upvotes: 1

Related Questions