Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'View call failed' error when creating an Invoice through DotNET

Status
Not open for further replies.

warrickvdb

Programmer
Oct 7, 2003
13
ZA
I am trying to create an invoice through DotNet. I copied the code from a Macro that was run through AccPac, and then made it DotNet 'friendly' (I have to use the enum's as the object wont accept string values).

The error occurs when I try to assign the IDITEM to the detail object.

Error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in aplaccpac.dll

Additional information: View call failed

Code:
Public Class clsAccPac

Enum Detail_1
CNTBTCH = 0
CNTITEM = 1
CNTLINE = 2
IDITEM = 4
AMTPRIC = 11
End Enum
Enum Detail_2
CNTBTCH = 0
CNTITEM = 1
CNTPAYM = 2
End Enum
Enum Header_1
CNTBTCH = 0
CNTITEM = 1
IDCUST = 2
IDINVC = 3
PROCESSCMD = 108
End Enum

Public Function createInvoice() As Integer

Dim intBatchNumber As Integer = 570

Dim session As New ACCPACXAPILib.xapiSession
session.Open("ADMIN", "ADMIN", "RMICON", Now.Today, 0)

Dim ARINVOICE3batch As ACCPACXAPILib.xapiView

Dim ARINVOICE3batchFields As ACCPACXAPILib.xapiFields
ARINVOICE3batch = session.OpenView("AR0031", "AR")
ARINVOICE3batchFields = ARINVOICE3batch.Fields

Dim ARINVOICE3header As ACCPACXAPILib.xapiView
Dim ARINVOICE3headerFields As ACCPACXAPILib.xapiFields
ARINVOICE3header = session.OpenView("AR0032", "AR")
ARINVOICE3headerFields = ARINVOICE3header.Fields

Dim ARINVOICE3detail1 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail1Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail1 = session.OpenView("AR0033", "AR")
ARINVOICE3detail1Fields = ARINVOICE3detail1.Fields

Dim ARINVOICE3detail2 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail2Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail2 = session.OpenView("AR0034", "AR")
ARINVOICE3detail2Fields = ARINVOICE3detail2.Fields


ARINVOICE3batch.Compose((ARINVOICE3header))
Dim arr(2) As Object
arr(0) = ARINVOICE3batch
arr(1) = ARINVOICE3detail1
arr(2) = ARINVOICE3detail2

ARINVOICE3header.Compose(arr)

Dim arr2(1) As Object
arr(0) = ARINVOICE3header
arr(1) = ARINVOICE3batch
ARINVOICE3detail1.Compose(arr2)

ARINVOICE3detail2.Compose((ARINVOICE3header))

ARINVOICE3batch.Init()

ARINVOICE3header.Init()
ARINVOICE3headerFields.Field(Header_1.IDCUST).Value = "1000003"
ARINVOICE3headerFields.Field(Header_1.IDINVC).Value = "INV0000000000000000006"
ARINVOICE3headerFields.Field(Header_1.PROCESSCMD).PutWithoutVerification("3")

ARINVOICE3detail1.Init()
ARINVOICE3detail1Fields.Field(Detail_1.IDITEM).Value = "ASSOC-CPT "
ARINVOICE3detail1Fields.Field(Detail_1.AMTPRIC).Value = "1200.000000"

ARINVOICE3detail2.Init()
ARINVOICE3detail2Fields.Field(Detail_2.CNTPAYM).PutWithoutVerification("-1")
ARINVOICE3detail1.Insert()

ARINVOICE3header.Insert()
ARINVOICE3header.Cancel()

End Function

End Class
 
If you are using VB.Net you may end up with lots of problems. The a4wcomm.dll (the xAPI) is not fully compatible with VB.Net. Some components of the ACCPAC 5.2 SDK (and maybe the 5.1 SDK) are but I am not sure which ones.

The tool of choice, right now, for the xAPI would be VB6. With the horror stories that I have read I haven't even tried using VB.Net yet. That doesn't mean you can't get it to work, I would just think that it will be more difficult. The code for the Marcos is VBA based on VB6, so you will require more syntax adjustments. There is even less documentation for using VB.Net (but how can you get less than almost none).

The error view call failed covers a lot of ground. It usually means that you are trying to enter a value that goes against the view constraints or keys. This could be data or relationship related. I would try removing the extra spaces or padding. You can also try using .putwithoutverification instead of .value.

Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Thanks. It looks like I will have to do it through VB 6.

Do you have, or do you know where I could find an example of an invoice been gererated? AccPac macro puts so much stuff in its code, it's hard to tell what is relevant and what is not.
 
Hear is a procedure that I use to export invoices from one program into Accpac. Hopefully it will make sence to you.

My session object (exSession) has a larger scope than just this procedure. 'm_udtInvoice' and 'm_udtjobs' are modular UDT arrays that hold the information to be exported.

Code:
Private Sub AddNew_Invoice(pInv As Integer)
'// Save the on account invoice details.
   Dim i As Integer, l_bolOK As Boolean, l_intDetail As Integer
   Dim ARINVOICEbatch As ACCPACXAPILib.xapiView
   Dim ARINVOICEheader As ACCPACXAPILib.xapiView
   Dim ARINVOICEdetail1 As ACCPACXAPILib.xapiView
   Dim ARINVOICEdetail2 As ACCPACXAPILib.xapiView
   Dim ARCUSTOMER As ACCPACXAPILib.xapiView
   
   On Error GoTo ERR_AddNewInvoice
   
   '// Set the views.
   Set ARINVOICEbatch = exSession.OpenView("AR0031", "AR")
   Set ARINVOICEheader = exSession.OpenView("AR0032", "AR")
   Set ARINVOICEdetail1 = exSession.OpenView("AR0033", "AR")
   Set ARINVOICEdetail2 = exSession.OpenView("AR0034", "AR")
   Set ARCUSTOMER = exSession.OpenView("AR0024", "AR")
   '// Compose the views.
   ARINVOICEbatch.Compose Array(ARINVOICEheader)
   ARINVOICEheader.Compose Array(ARINVOICEbatch, ARINVOICEdetail1, ARINVOICEdetail2)
   ARINVOICEdetail1.Compose Array(ARINVOICEheader, ARINVOICEbatch)
   ARINVOICEdetail2.Compose Array(ARINVOICEheader)
 
   '// Get the customer information, to be entered in the invoice.
   With ARCUSTOMER
      .Browse "IDCUST = " & m_udtInvoice(pInv).AccPacID & "", True
      If Not .Fetch Then MsgBox "Customer information could not be found.", vbOKOnly + vbExclamation, "Information Missing"
   End With
   
   '// Get the batch number, separate function that gets and existing batch number or creates a new one.
   If m_lngInvBatch = 0 Then Fetch_InvBatch
   
   '// Open the batch.
   ARINVOICEbatch.Browse "CNTBTCH = " & m_lngInvBatch & "", True
   If ARINVOICEbatch.Fetch Then
      l_bolOK = True
      '// Header table.
      With ARINVOICEheader
         .Init
         m_intInvEntry = m_intInvEntry + 1   '// modular variable to keep track of the enties (invoices)
         .Fields("CNTITEM").value = m_intInvEntry
         .Fields("IDCUST").value = m_udtInvoice(pInv).AccPacID
         .Fields("IDINVC").value = m_udtInvoice(pInv).inNumber
         .Fields("TEXTTRX").value = 1  '// Invoice.
         .Fields("IDTRX").value = 12   '// Summary entered.
         .Fields("INVCDESC").value = "WBSS Invoice: " & m_udtInvoice(pInv).inNumber
         .Fields("ORDRNBR").value = "WBSS Work Order: " & m_udtInvoice(pInv).inWorkOrder
         .Fields("CUSTPO").value = m_udtInvoice(pInv).inCustomerPO
         .Fields("DATEINVC").value = m_udtInvoice(pInv).inInvDate
         .Fields("TERMCODE").value = ARCUSTOMER.Fields("CODETERM").value
         .Fields("SWMANTX").value = 0   '// Do not calculate tax.
         .Fields("CODETAXGRP").value = ARCUSTOMER.Fields("CODETAXGRP").value
         .Fields("TAXSTTS1").value = ARCUSTOMER.Fields("TAXSTTS1").value
         .Fields("TAXSTTS2").value = ARCUSTOMER.Fields("TAXSTTS2").value
         .Fields("TAXSTTS3").value = ARCUSTOMER.Fields("TAXSTTS3").value
         .Fields("TAXSTTS4").value = ARCUSTOMER.Fields("TAXSTTS4").value
         .Fields("TAXSTTS5").value = ARCUSTOMER.Fields("TAXSTTS5").value
         .Fields("BASETAX1").value = Round(m_sngTaxBase, 2)
         .Fields("BASETAX2").value = Round(m_sngTaxBase, 2)
         .Fields("BASETAX3").value = 0
         .Fields("BASETAX4").value = 0
         .Fields("BASETAX5").value = 0
         .Fields("AMTTAX1").value = m_udtInvoice(pInv).inGST
         .Fields("AMTTAX2").value = m_udtInvoice(pInv).inPST
         .Fields("AMTTAX3").value = 0
         .Fields("AMTTAX4").value = 0
         .Fields("AMTTAX5").value = 0
      End With
      '// Loop through the details updating the various gl accounts.
      l_intDetail = 0
      For i = 0 To UBound(m_udtJobs)
         With ARINVOICEdetail1
            .Init
            .Fields("IDACCTREV").value = m_udtJobs(i).joGLRevenue
            .Fields("CNTLINE").value = l_intDetail
            .Fields("AMTEXTN").value = (m_udtJobs(i).joPriceEach * m_udtJobs(i).joQuantity)
            .Insert
            l_intDetail = l_intDetail - 1
            .Init
            .Fields("IDACCTREV").value = m_udtJobs(i).joGLInventory
            .Fields("CNTLINE").value = l_intDetail
            .Fields("AMTEXTN").value = (m_udtJobs(i).joCostEach * m_udtJobs(i).joQuantity) * -1
            .Insert
            l_intDetail = l_intDetail - 1
            .Init
            .Fields("IDACCTREV").value = m_udtJobs(i).joGLCOGS
            .Fields("CNTLINE").value = l_intDetail
            .Fields("AMTEXTN").value = (m_udtJobs(i).joCostEach * m_udtJobs(i).joQuantity)
            .Insert
            l_intDetail = l_intDetail - 1
         End With
      Next i
      '// AR transfers into ARIBS.
      ARINVOICEdetail2.Init
      ARINVOICEdetail2.Fields("DATEDUE").value = ARINVOICEheader.Fields("DATEDUE").value
        
      '// Update the database.
      ARINVOICEheader.Insert
      ARINVOICEdetail2.Insert
      ARINVOICEbatch.Update
   End If
   '// Destroy the objects.
   ARINVOICEheader.Cancel
   ARINVOICEdetail2.Cancel
   ARINVOICEbatch.Cancel
   ARCUSTOMER.Cancel
   Set ARINVOICEbatch = Nothing
   Set ARINVOICEheader = Nothing
   Set ARINVOICEdetail1 = Nothing
   Set ARINVOICEdetail2 = Nothing
   Set ARCUSTOMER = Nothing
   
   If l_bolOK Then
      Update_InvoiceExport m_udtInvoice(pInv).InvoiceID, m_udtInvoice(pInv).inNumber
   End If
   Exit Sub

ERR_AddNewInvoice:
   Dim Errors As xapiErrors
   Dim Error As Variant
   
   Set Errors = exSession.Errors
   If Errors.count = 0 Then
      MsgBox Err.Number & ": " & Err.Description, , "AccPac Error"
   Else
      For Each Error In Errors
         If Error.Priority = 2 Or Error.Priority = 1 Then
            RaiseEvent SendStatus("Warning on On Account Invoice with Invoice:" & m_udtInvoice(pInv).inNumber & ".")
            LogEvent eLogError, "ACCPAC Warning, " & Error.Description & " on On Account Invoice with Invoice:" & m_udtInvoice(pInv).inNumber & "."
            RaiseEvent SendWarning
         Else
            RaiseEvent SendStatus("Transfer Failure on On Account Invoice with Invoice:" & m_udtInvoice(pInv).inNumber & ".")
            LogEvent eLogError, "ACCPAC Transfer Failure, " & Error.Description & " on On Account Invoice with Invoice: " & m_udtInvoice(pInv).inNumber & "."
            RaiseEvent SendFailure
            m_bolInvError = True
            l_bolOK = False
         End If
         'MsgBox Error.Priority & ": " & Error.Description
      Next
      m_bolError = True
      Errors.Clear
   End If
   Set Errors = Nothing
   Resume Next
End Sub


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top