Hi,
I am writing a program to import invoices into ACCPAC batch. Following is the code fragment that import (should import ) data into ACCPAC.
1. I am not sure how all this VIEWs thing works - I've seen in sample macros that view gets declared, initialize and COMPOSED. MY question: I would logically get why declared and initialized, but why do we need composed, what is happening at initialization time?
2. I got error messages (inside of the code in red):
1st - I don't see why there is 1st error message?
2nd - The Amount ACCPAC talks in the second errorMSG is a field that is a part of APINVOICINGdetail1 view, but I can not update two views at the same time. Probably I have to Compose my views differently, but I don't really know what composition do?
I would appreciate any help,
P.S. I saw a post not long ago: some one was talking about 'creating program by the book, Declare views, initialize, COMPOSE' - any Idea where I can look up into that kind of book,.. well any kind will do?!
Thank you for your posts
Dim APINVOICEbatch As AccpacCOMAPI.AccpacView
Dim APINVOICEbatchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0020", APINVOICEbatch
Set APINVOICEbatchFields = APINVOICEbatch.Fields
Dim APINVOICEheader As AccpacCOMAPI.AccpacView
Dim APINVOICEheaderFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0021", APINVOICEheader
Set APINVOICEheaderFields = APINVOICEheader.Fields
Dim APINVOICEdetail1 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0022", APINVOICEdetail1
Set APINVOICEdetail1Fields = APINVOICEdetail1.Fields
Dim APINVOICEdetail2 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0023", APINVOICEdetail2
Set APINVOICEdetail2Fields = APINVOICEdetail2.Fields
APINVOICEbatch.Compose Array(APINVOICEheader)
APINVOICEheader.Compose Array(APINVOICEbatch, APINVOICEdetail1, APINVOICEdetail2)
APINVOICEdetail1.Compose Array(APINVOICEheader, APINVOICEbatch)
APINVOICEdetail2.Compose Array(APINVOICEheader)
'ADDING DATA TO BATCH**************
' Batch Number
APINVOICEbatchFields("CNTBTCH").PutWithoutVerification ("0")
APINVOICEbatch.Init
'Getting new Batch Number
BatchNo = APINVOICEbatchFields("CNTBTCH").Value
'Adding comment to the new Batch
APINVOICEbatchFields("BTCHDESC").PutWithoutVerification (BatchDescription)
'Setting up the number of records imported
APINVOICEbatchFields("CNTINVCENT").PutWithoutVerification (rstSourceDB.RecordCount)
APINVOICEbatch.Update
'counter for record number
Dim i As Integer
i = 1
'ADDING DATA TO HEADER
rstSourceDB.MoveFirst
Do
APINVOICEheader.Init
APINVOICEheaderFields("CNTBTCH").Value = BatchNo
APINVOICEheaderFields("CNTITEM").Value = i
APINVOICEheaderFields("IDVEND").Value = rstSourceDB!VENDORID
APINVOICEheaderFields("IDINVC").Value = rstSourceDB![Contractor Invoice No]
APINVOICEheaderFields("LASTLINE").Value = 1
APINVOICEheaderFields("ORDRNBR").Value = rstSourceDB![OCHC Workorder No]
'APINVOICEheaderFields("PONBR").Value = rstSourceDB![Contract No]
APINVOICEheaderFields("INVCDESC").Value = rstSourceDB![Invoice Description]
APINVOICEheaderFields("DATEINVC").Value = rstSourceDB![Invoice Date]
APINVOICEheaderFields("DATEDUE").Value = rstSourceDB![Invoice Date]
'APINVOICEheaderFields("AMTDUE").Value = rstSourceDB![Gross Payment]
APINVOICEheaderFields("AMTGROSTOT").Value = rstSourceDB![Gross Payment]
'My program crashes on Update, 2 errors:
1. "Invoice. Record has been modified by another program."
2. "Warning. The distributed amount does not equal the document total."
APINVOICEheader.Update
i = i + 1
rstSourceDB.MoveNext
Loop While rstSourceDB.EOF = False
Convert = True
I am writing a program to import invoices into ACCPAC batch. Following is the code fragment that import (should import ) data into ACCPAC.
1. I am not sure how all this VIEWs thing works - I've seen in sample macros that view gets declared, initialize and COMPOSED. MY question: I would logically get why declared and initialized, but why do we need composed, what is happening at initialization time?
2. I got error messages (inside of the code in red):
1st - I don't see why there is 1st error message?
2nd - The Amount ACCPAC talks in the second errorMSG is a field that is a part of APINVOICINGdetail1 view, but I can not update two views at the same time. Probably I have to Compose my views differently, but I don't really know what composition do?
I would appreciate any help,
P.S. I saw a post not long ago: some one was talking about 'creating program by the book, Declare views, initialize, COMPOSE' - any Idea where I can look up into that kind of book,.. well any kind will do?!
Thank you for your posts
Dim APINVOICEbatch As AccpacCOMAPI.AccpacView
Dim APINVOICEbatchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0020", APINVOICEbatch
Set APINVOICEbatchFields = APINVOICEbatch.Fields
Dim APINVOICEheader As AccpacCOMAPI.AccpacView
Dim APINVOICEheaderFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0021", APINVOICEheader
Set APINVOICEheaderFields = APINVOICEheader.Fields
Dim APINVOICEdetail1 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0022", APINVOICEdetail1
Set APINVOICEdetail1Fields = APINVOICEdetail1.Fields
Dim APINVOICEdetail2 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0023", APINVOICEdetail2
Set APINVOICEdetail2Fields = APINVOICEdetail2.Fields
APINVOICEbatch.Compose Array(APINVOICEheader)
APINVOICEheader.Compose Array(APINVOICEbatch, APINVOICEdetail1, APINVOICEdetail2)
APINVOICEdetail1.Compose Array(APINVOICEheader, APINVOICEbatch)
APINVOICEdetail2.Compose Array(APINVOICEheader)
'ADDING DATA TO BATCH**************
' Batch Number
APINVOICEbatchFields("CNTBTCH").PutWithoutVerification ("0")
APINVOICEbatch.Init
'Getting new Batch Number
BatchNo = APINVOICEbatchFields("CNTBTCH").Value
'Adding comment to the new Batch
APINVOICEbatchFields("BTCHDESC").PutWithoutVerification (BatchDescription)
'Setting up the number of records imported
APINVOICEbatchFields("CNTINVCENT").PutWithoutVerification (rstSourceDB.RecordCount)
APINVOICEbatch.Update
'counter for record number
Dim i As Integer
i = 1
'ADDING DATA TO HEADER
rstSourceDB.MoveFirst
Do
APINVOICEheader.Init
APINVOICEheaderFields("CNTBTCH").Value = BatchNo
APINVOICEheaderFields("CNTITEM").Value = i
APINVOICEheaderFields("IDVEND").Value = rstSourceDB!VENDORID
APINVOICEheaderFields("IDINVC").Value = rstSourceDB![Contractor Invoice No]
APINVOICEheaderFields("LASTLINE").Value = 1
APINVOICEheaderFields("ORDRNBR").Value = rstSourceDB![OCHC Workorder No]
'APINVOICEheaderFields("PONBR").Value = rstSourceDB![Contract No]
APINVOICEheaderFields("INVCDESC").Value = rstSourceDB![Invoice Description]
APINVOICEheaderFields("DATEINVC").Value = rstSourceDB![Invoice Date]
APINVOICEheaderFields("DATEDUE").Value = rstSourceDB![Invoice Date]
'APINVOICEheaderFields("AMTDUE").Value = rstSourceDB![Gross Payment]
APINVOICEheaderFields("AMTGROSTOT").Value = rstSourceDB![Gross Payment]
'My program crashes on Update, 2 errors:
1. "Invoice. Record has been modified by another program."
2. "Warning. The distributed amount does not equal the document total."
APINVOICEheader.Update
i = i + 1
rstSourceDB.MoveNext
Loop While rstSourceDB.EOF = False
Convert = True