By browsing these forums and playing with the Macro recording in Accpac, I think I've come pretty close, but I get the following error;
"View: AP0021. View call failed"
The error is thrown on the line "hHeader.Insert". My current code is as follows (tried a lot of different things, and always get that error on the insert of the header)..
any help / pointers / advice is appreciated.
Dim hSession As xapiSession
Dim hPost As xapiView
Dim hBatch As xapiView
Dim hHeader As xapiView
Dim hDetail1 As xapiView
Dim hDetail2 As xapiView
Set hSession = New xapiSession
hSession.Open "MARK", "MARK", "SAMINC", Date, 0
If Not IsNull(hSession) Then
Set hPost = hSession.OpenView("AP0039", "AP"
Set hBatch = hSession.OpenView("AP0020", "AP"
Set hHeader = hSession.OpenView("AP0021", "AP"
Set hDetail1 = hSession.OpenView("AP0022", "AP"
Set hDetail2 = hSession.OpenView("AP0023", "AP"
hBatch.Compose Array(hHeader)
hHeader.Compose Array(hBatch, hDetail1, hDetail2)
hDetail1.Compose Array(hHeader, hBatch)
hDetail2.Compose Array(hHeader)
hBatch.Fields("CNTBTCH".PutWithoutVerification ("0"
hBatch.Init
hBatch.Fields("BTCHDESC".Value = "New Batch " & Format(Date, "yyyy-MM-dd"
hBatch.Fields("BTCHTYPE".Value = 2
hBatch.Update
End If
hHeader.Init
With hHeader
.Fields("CNTITEM".Value = 1 ' !
.Fields("IDVEND".Value = "1200"
.Fields("IDINVC".Value = 1 ' !
.Fields("TEXTTRX".Value = 1
.Fields("IDTRX".Value = 12
.Fields("INVCDESC".Value = "yo - description here."
.Fields("ORDRNBR".Value = "order number"
.Fields("PONBR".Value = "P.O. Number"
.Fields("DATEINVC".Value = Date
.Fields("SWTAXBL".Value = 0
.Fields("BASETAX1".Value = 0
.Fields("BASETAX2".Value = 0
.Fields("BASETAX3".Value = 0
.Fields("BASETAX4".Value = 0
.Fields("BASETAX5".Value = 0
.Fields("AMTTAX1".Value = 0
.Fields("AMTTAX2".Value = 0
.Fields("AMTTAX3".Value = 0
.Fields("AMTTAX4".Value = 0
.Fields("AMTTAX5".Value = 0
End With
hDetail1.Init
With hDetail1
.Fields("CNTITEM".PutWithoutVerification (hHeader.Fields("CNTITEM".Value)
.Fields("CNTLINE".PutWithoutVerification ("0"
.Fields("CNTBTCH".PutWithoutVerification (hBatch.Fields("CNTBTCH".Value)
.Fields("IDDIST".PutWithoutVerification ("INV"
.Fields("AMTDIST".Value = "225.000"
End With
hDetail1.Insert
hHeader.Insert
hDetail1.Cancel
hHeader.Cancel
Set hPost = Nothing
Set hBatch = Nothing
Set hHeader = Nothing
Set hDetail1 = Nothing
Set hDetail2 = Nothing
"View: AP0021. View call failed"
The error is thrown on the line "hHeader.Insert". My current code is as follows (tried a lot of different things, and always get that error on the insert of the header)..
any help / pointers / advice is appreciated.
Dim hSession As xapiSession
Dim hPost As xapiView
Dim hBatch As xapiView
Dim hHeader As xapiView
Dim hDetail1 As xapiView
Dim hDetail2 As xapiView
Set hSession = New xapiSession
hSession.Open "MARK", "MARK", "SAMINC", Date, 0
If Not IsNull(hSession) Then
Set hPost = hSession.OpenView("AP0039", "AP"
Set hBatch = hSession.OpenView("AP0020", "AP"
Set hHeader = hSession.OpenView("AP0021", "AP"
Set hDetail1 = hSession.OpenView("AP0022", "AP"
Set hDetail2 = hSession.OpenView("AP0023", "AP"
hBatch.Compose Array(hHeader)
hHeader.Compose Array(hBatch, hDetail1, hDetail2)
hDetail1.Compose Array(hHeader, hBatch)
hDetail2.Compose Array(hHeader)
hBatch.Fields("CNTBTCH".PutWithoutVerification ("0"
hBatch.Init
hBatch.Fields("BTCHDESC".Value = "New Batch " & Format(Date, "yyyy-MM-dd"
hBatch.Fields("BTCHTYPE".Value = 2
hBatch.Update
End If
hHeader.Init
With hHeader
.Fields("CNTITEM".Value = 1 ' !
.Fields("IDVEND".Value = "1200"
.Fields("IDINVC".Value = 1 ' !
.Fields("TEXTTRX".Value = 1
.Fields("IDTRX".Value = 12
.Fields("INVCDESC".Value = "yo - description here."
.Fields("ORDRNBR".Value = "order number"
.Fields("PONBR".Value = "P.O. Number"
.Fields("DATEINVC".Value = Date
.Fields("SWTAXBL".Value = 0
.Fields("BASETAX1".Value = 0
.Fields("BASETAX2".Value = 0
.Fields("BASETAX3".Value = 0
.Fields("BASETAX4".Value = 0
.Fields("BASETAX5".Value = 0
.Fields("AMTTAX1".Value = 0
.Fields("AMTTAX2".Value = 0
.Fields("AMTTAX3".Value = 0
.Fields("AMTTAX4".Value = 0
.Fields("AMTTAX5".Value = 0
End With
hDetail1.Init
With hDetail1
.Fields("CNTITEM".PutWithoutVerification (hHeader.Fields("CNTITEM".Value)
.Fields("CNTLINE".PutWithoutVerification ("0"
.Fields("CNTBTCH".PutWithoutVerification (hBatch.Fields("CNTBTCH".Value)
.Fields("IDDIST".PutWithoutVerification ("INV"
.Fields("AMTDIST".Value = "225.000"
End With
hDetail1.Insert
hHeader.Insert
hDetail1.Cancel
hHeader.Cancel
Set hPost = Nothing
Set hBatch = Nothing
Set hHeader = Nothing
Set hDetail1 = Nothing
Set hDetail2 = Nothing