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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting an Invoice into an AccPac Batch 1

Status
Not open for further replies.

Bladzok

Programmer
Dec 19, 2002
5
0
0
ZA
Hi all,

Been reading these posts and found it to be the best info on the web at the moment. Does anyone have some VB code to post an invoice into an open batch in AccPac.

Can anyone help me with why I can't view the recorded Macros (in fact the Macro designer just won't open at all)

Thanks

 
Did you get sorted out or are you still looking for an answer?
 
I tried to do the same thing from Access 2000, but finally decided it was easier just to do a manual import from AccPac. Before I run the import I check the next available batch number in AccPac, then update all my waiting-to-be-exported invoices with this batch number in Access. Then I go and run the import from AccPac.
 
Posting an AR invoice into accpac via VB is simple once you get the syntax down. You can use existing batches, create new ones almost anything. You will need to have the correct views declared and composed properly.

Post the code you have so far and I will have a look. Thanks and Good Luck!

zemp
 
>Thanks for the reply. My main problem was that I couldn't get the
>Macro functionality working on AccPac. Now that that is working, it is
>very easy to see what code the recorded macro generates, add a few
>sessions here and there and off it goes.
>
>One question I do have at the moment is, how do you get the invoice
>number back when you create an invoice (see code below)
>
>Thanks
>
>Peter Munnings
>alias: Bladzok
>
>
>On Error GoTo ACCPACErrorHandler
>Dim session As ACCPACXAPILib.IxapiSession
>
>Set session = CreateObject("ACCPAC.xapiSession")
>session.Open "ADMIN", "ADMIN", "SAMINC", Date, 0
>
>Dim ARINVOICE3batch As ACCPACXAPILib.xapiView
>Dim ARINVOICE3batchFields As ACCPACXAPILib.xapiFields
>Set ARINVOICE3batch = session.OpenView("AR0031", "AR")
>Set ARINVOICE3batchFields = ARINVOICE3batch.Fields
>
>Dim ARINVOICE3header As ACCPACXAPILib.xapiView
>Dim ARINVOICE3headerFields As ACCPACXAPILib.xapiFields
>Set ARINVOICE3header = session.OpenView("AR0032", "AR")
>Set ARINVOICE3headerFields = ARINVOICE3header.Fields
>
>Dim ARINVOICE3detail1 As ACCPACXAPILib.xapiView
>Dim ARINVOICE3detail1Fields As ACCPACXAPILib.xapiFields
>Set ARINVOICE3detail1 = session.OpenView("AR0033", "AR")
>Set ARINVOICE3detail1Fields = ARINVOICE3detail1.Fields
>
>Dim ARINVOICE3detail2 As ACCPACXAPILib.xapiView
>Dim ARINVOICE3detail2Fields As ACCPACXAPILib.xapiFields
>Set ARINVOICE3detail2 = session.OpenView("AR0034", "AR")
>Set ARINVOICE3detail2Fields = ARINVOICE3detail2.Fields
>
>Dim ARINVOICE3batchComps(0) As ACCPACXAPILib.xapiView
>Set ARINVOICE3batchComps(0) = ARINVOICE3header ARINVOICE3batch.Compose
>ARINVOICE3batchComps
>
>Dim ARINVOICE3headerComps(2) As ACCPACXAPILib.xapiView
>Set ARINVOICE3headerComps(0) = ARINVOICE3batch
>Set ARINVOICE3headerComps(1) = ARINVOICE3detail1
>Set ARINVOICE3headerComps(2) = ARINVOICE3detail2
>ARINVOICE3header.Compose ARINVOICE3headerComps
>
>Dim ARINVOICE3detail1Comps(1) As ACCPACXAPILib.xapiView
>Set ARINVOICE3detail1Comps(0) = ARINVOICE3header
>Set ARINVOICE3detail1Comps(1) = ARINVOICE3batch
>ARINVOICE3detail1.Compose ARINVOICE3detail1Comps
>
>Dim ARINVOICE3detail2Comps(0) As ACCPACXAPILib.xapiView
>Set ARINVOICE3detail2Comps(0) = ARINVOICE3header
>ARINVOICE3detail2.Compose ARINVOICE3detail2Comps
>
>ARINVOICE3batchFields("CNTBTCH").PutWithoutVerification
>(CStr(lngBatchNo)) ' Batch Number
>
>ARINVOICE3batch.Read
>ARINVOICE3headerFields("CNTITEM").PutWithoutVerification ("0") '
>Entry Number
>ARINVOICE3header.Browse "(CNTBTCH = " & CStr(lngBatchNo) & " )",
>1
>ARINVOICE3header.Fetch
>ARINVOICE3detail1.Cancel
>ARINVOICE3detail2.Cancel
>ARINVOICE3headerFields("CNTITEM").PutWithoutVerification ("0") '
>Entry Number
>ARINVOICE3header.Init
>
>ARINVOICE3headerFields("IDCUST").Value = strCustNo
>' Customer Number
>ARINVOICE3headerFields("INVCDESC").Value = strDescription '
>Invoice Description
>ARINVOICE3headerFields("SPECINST").Value = strSpecInstr
>
>ARINVOICE3detail1.Order = 0
>ARINVOICE3detail1.Init
>
>For i = 1 To UBound(strDistCode)
> ARINVOICE3detail1Fields("IDDIST").Value = strDistCode(i) '
>Distribution Code
> If strDetailDesc(i) <> &quot;None&quot; Then
> ARINVOICE3detail1Fields(&quot;TEXTDESC&quot;).Value = strDetailDesc(i)
> End If
> ARINVOICE3detail1Fields(&quot;AMTEXTN&quot;).Value = strAmount(i)
>' Extended Amount (with TIP)
> ARINVOICE3detail1Fields(&quot;COMMENT&quot;).Value = strComment(i)
>
> ARINVOICE3detail1.Insert
>Next i
>
>ARINVOICE3headerFields(&quot;TEXTOPFL2&quot;).Value = &quot;0&quot; '
>Optional Field 2
>
>ARINVOICE3headerFields(&quot;TEXTOPFL3&quot;).Value = &quot;&quot; '
>Optional Field 3
>
>ARINVOICE3header.Insert
>
>ARINVOICE3headerFields(&quot;TEXTOPFL3&quot;).Value = &quot;&quot; '
>Optional Field 3
>
>
>Exit Sub
>
>ACCPACErrorHandler:
> Dim Error As Variant
>
> If session.Errors.Count = 0 Then
> MsgBox Err.Description
> Else
> For Each Error In session.Errors
> MsgBox Error.Description
> Next
> session.Errors.Clear
> End If
>
> Resume Next
 
Thanks for the reply. My main problem was that I couldn’t get the Macro functionality working on AccPac. Now that that is working, it is very easy to see what code the recorded macro generates, add a few sessions here and there and off it goes.



One question I do have at the moment is, how do you get the invoice number back when you create an invoice (see code below)



Thanks




On Error GoTo ACCPACErrorHandler

Dim session As ACCPACXAPILib.IxapiSession



Set session = CreateObject(&quot;ACCPAC.xapiSession&quot;)

session.Open &quot;ADMIN&quot;, &quot;ADMIN&quot;, &quot;SAMINC&quot;, Date, 0



Dim ARINVOICE3batch As ACCPACXAPILib.xapiView

Dim ARINVOICE3batchFields As ACCPACXAPILib.xapiFields

Set ARINVOICE3batch = session.OpenView(&quot;AR0031&quot;, &quot;AR&quot;)

Set ARINVOICE3batchFields = ARINVOICE3batch.Fields



Dim ARINVOICE3header As ACCPACXAPILib.xapiView

Dim ARINVOICE3headerFields As ACCPACXAPILib.xapiFields

Set ARINVOICE3header = session.OpenView(&quot;AR0032&quot;, &quot;AR&quot;)

Set ARINVOICE3headerFields = ARINVOICE3header.Fields



Dim ARINVOICE3detail1 As ACCPACXAPILib.xapiView

Dim ARINVOICE3detail1Fields As ACCPACXAPILib.xapiFields

Set ARINVOICE3detail1 = session.OpenView(&quot;AR0033&quot;, &quot;AR&quot;)

Set ARINVOICE3detail1Fields = ARINVOICE3detail1.Fields



Dim ARINVOICE3detail2 As ACCPACXAPILib.xapiView

Dim ARINVOICE3detail2Fields As ACCPACXAPILib.xapiFields

Set ARINVOICE3detail2 = session.OpenView(&quot;AR0034&quot;, &quot;AR&quot;)

Set ARINVOICE3detail2Fields = ARINVOICE3detail2.Fields



Dim ARINVOICE3batchComps(0) As ACCPACXAPILib.xapiView

Set ARINVOICE3batchComps(0) = ARINVOICE3header

ARINVOICE3batch.Compose ARINVOICE3batchComps



Dim ARINVOICE3headerComps(2) As ACCPACXAPILib.xapiView

Set ARINVOICE3headerComps(0) = ARINVOICE3batch

Set ARINVOICE3headerComps(1) = ARINVOICE3detail1

Set ARINVOICE3headerComps(2) = ARINVOICE3detail2

ARINVOICE3header.Compose ARINVOICE3headerComps



Dim ARINVOICE3detail1Comps(1) As ACCPACXAPILib.xapiView

Set ARINVOICE3detail1Comps(0) = ARINVOICE3header

Set ARINVOICE3detail1Comps(1) = ARINVOICE3batch

ARINVOICE3detail1.Compose ARINVOICE3detail1Comps



Dim ARINVOICE3detail2Comps(0) As ACCPACXAPILib.xapiView

Set ARINVOICE3detail2Comps(0) = ARINVOICE3header

ARINVOICE3detail2.Compose ARINVOICE3detail2Comps



ARINVOICE3batchFields(&quot;CNTBTCH&quot;).PutWithoutVerification (CStr(lngBatchNo)) ' Batch Number



ARINVOICE3batch.Read

ARINVOICE3headerFields(&quot;CNTITEM&quot;).PutWithoutVerification (&quot;0&quot;) ' Entry Number

ARINVOICE3header.Browse &quot;(CNTBTCH = &quot; & CStr(lngBatchNo) & &quot; )&quot;, 1

ARINVOICE3header.Fetch

ARINVOICE3detail1.Cancel

ARINVOICE3detail2.Cancel

ARINVOICE3headerFields(&quot;CNTITEM&quot;).PutWithoutVerification (&quot;0&quot;) ' Entry Number

ARINVOICE3header.Init



ARINVOICE3headerFields(&quot;IDCUST&quot;).Value = strCustNo ' Customer Number

ARINVOICE3headerFields(&quot;INVCDESC&quot;).Value = strDescription ' Invoice Description

ARINVOICE3headerFields(&quot;SPECINST&quot;).Value = strSpecInstr



ARINVOICE3detail1.Order = 0

ARINVOICE3detail1.Init



For i = 1 To UBound(strDistCode)

ARINVOICE3detail1Fields(&quot;IDDIST&quot;).Value = strDistCode(i) ' Distribution Code

If strDetailDesc(i) <> &quot;None&quot; Then

ARINVOICE3detail1Fields(&quot;TEXTDESC&quot;).Value = strDetailDesc(i)

End If

ARINVOICE3detail1Fields(&quot;AMTEXTN&quot;).Value = strAmount(i) ' Extended Amount (with TIP)

ARINVOICE3detail1Fields(&quot;COMMENT&quot;).Value = strComment(i)



ARINVOICE3detail1.Insert

Next i



ARINVOICE3headerFields(&quot;TEXTOPFL2&quot;).Value = &quot;0&quot; ' Optional Field 2



ARINVOICE3headerFields(&quot;TEXTOPFL3&quot;).Value = &quot;&quot; ' Optional Field 3



ARINVOICE3header.Insert



ARINVOICE3headerFields(&quot;TEXTOPFL3&quot;).Value = &quot;&quot; ' Optional Field 3





Exit Sub



ACCPACErrorHandler:

Dim Error As Variant



If session.Errors.Count = 0 Then

MsgBox Err.Description

Else

For Each Error In session.Errors

MsgBox Error.Description

Next

session.Errors.Clear

End If



Resume Next
 
The only way that I know of how to get the AccPac generated invoice number is to make another call to the database and fetch it.
Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top