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!

ACCPAC 54A question on posting orders.

Status
Not open for further replies.

V3nd3tta

Programmer
Jul 22, 2008
21
ZA
First of all, Hallo I am new to ACCPAC and so also new to this forumns....I sound like Alcohol anonymous person....lol..anycase.

I am trying to Insert Payments into Accpca using c#. I got it to work on the Purchase orders,by just recreating the macro using c#, and it seems to work 100% , but when recreating the macro in C# for the payments I get com exception on the record create and update see code at the bottom

ACCPAC.Advantage.Session AccSession = new ACCPAC.Advantage.Session();
AccSession.Init("", "AP", "AP3100", "54A");

AccSession.Open("*****", "*****", "****", DateTime.Now.AddYears(-1), 0);

ACCPAC.Advantage.DBLink PmtCompLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
ACCPAC.Advantage.DBLink PmtSysLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.System, ACCPAC.Advantage.DBLinkFlags.ReadWrite);

bool temp = false;
ACCPAC.Advantage.ViewFields APPaymentBatchFields;
ACCPAC.Advantage.View APPaymentBatch = PmtCompLink.OpenView("AP0030");
APPaymentBatchFields = APPaymentBatch.Fields;

ACCPAC.Advantage.ViewFields APPaymentHeaderFields;
ACCPAC.Advantage.View APPaymentHeader = PmtCompLink.OpenView("AP0031");//header
APPaymentHeaderFields = APPaymentHeader.Fields;

ACCPAC.Advantage.ViewFields APPaymentDetail1Fields;
ACCPAC.Advantage.View APPaymentDetail1 = PmtCompLink.OpenView("AP0033"); //DETAILVIEWS
APPaymentDetail1Fields = APPaymentDetail1.Fields;

ACCPAC.Advantage.ViewFields APPaymentDetail2Fields;
ACCPAC.Advantage.View APPaymentDetail2 = PmtCompLink.OpenView("AP0034");
APPaymentDetail2Fields = APPaymentDetail2.Fields;

ACCPAC.Advantage.ViewFields APPaymentDetail3Fields;
ACCPAC.Advantage.View APPaymentDetail3 = PmtCompLink.OpenView("AP0032");
APPaymentDetail3Fields = APPaymentDetail3.Fields;

ACCPAC.Advantage.ViewFields APPaymentDetail4Fields;
ACCPAC.Advantage.View APPaymentDetail4 = PmtCompLink.OpenView("AP0048");
APPaymentDetail4Fields = APPaymentDetail4.Fields;

ACCPAC.Advantage.ViewFields APPaymentDetail5Fields;
ACCPAC.Advantage.View APPaymentDetail5 = PmtCompLink.OpenView("AP0406");
APPaymentDetail5Fields = APPaymentDetail5.Fields;

ACCPAC.Advantage.View[] APPaymentBatch1 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentBatch.Compose(APPaymentBatch1);

ACCPAC.Advantage.View[] APHeaderBatch = new ACCPAC.Advantage.View[4] { APPaymentBatch, APPaymentDetail3, APPaymentDetail1, APPaymentDetail5 };
APPaymentHeader.Compose(APHeaderBatch);

//Compose detail views.
ACCPAC.Advantage.View[] APDetailBatch1 = new ACCPAC.Advantage.View[3] { APPaymentHeader, APPaymentDetail2, APPaymentDetail4 };
APPaymentDetail1.Compose(APDetailBatch1);
ACCPAC.Advantage.View[] APDetailBatch2 = new ACCPAC.Advantage.View[1] { APPaymentDetail1 };
APPaymentDetail2.Compose(APDetailBatch2);
ACCPAC.Advantage.View[] APDetailBatch3 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail3.Compose(APDetailBatch3);
ACCPAC.Advantage.View[] APDetailBatch4 = new ACCPAC.Advantage.View[5] { APPaymentBatch, APPaymentHeader, APPaymentDetail3, APPaymentDetail1, APPaymentDetail2 };
APPaymentDetail4.Compose(APDetailBatch4);
ACCPAC.Advantage.View[] APDetailBatch5 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail5.Compose(APDetailBatch5);

temp = APPaymentBatch.Exists;
APPaymentBatch.RecordClear();

APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false); //batch selector

APPaymentHeaderFields.FieldByName("BTCHTYPE").SetValue("PY", false); //batch type/
APPaymentDetail3Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail1Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail2Fields.FieldByName("BATCHTYPE").SetValue("PY", false);

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentBatch.Browse(@"((PAYMTYPE='PY') AND ((BATCHSTAT=1) OR (BATCHSTAT=7) OR (BATCHSTAT=8)))", true);

APPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false);
APPaymentBatchFields.FieldByName("CNTBTCH").SetValue(0, false);

temp = APPaymentBatch.Exists;
APPaymentBatch.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert );

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

//***********************************
//This gives com exeption

APPaymentHeader.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);


//****************************************


//APPAYMENT1header.RecordCreate 0
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentBatchFields.FieldByName("BATCHDESC").SetValue("SDFSDFSD", false);

//*********************************************
//********THIS IS WHERE I GET THE EXCEPTION****

APPaymentBatch.Update(); //Create Batch Header


//*********************************************
//*********************************************

APPaymentHeaderFields.FieldByName("TEXTRMIT").SetValue("sdsds", false);
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
APPaymentHeaderFields.FieldByName("RMITTYPE").SetValue("4", false);
APPaymentDetail1.Cancel();

APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentHeaderFields.FieldByName("IDVEND").SetValue("GOE-1234", false);
APPaymentDetail1.Cancel();
APPaymentHeaderFields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("0", false);

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentHeaderFields.FieldByName("TXTRMITREF").SetValue("sdsdsd", false);

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentHeaderFields.FieldByName("IDINVCMTCH").SetValue("sdsds", false); //matching document number

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentDetail3.Exists;

APPaymentDetail3.RecordClear();
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);

APPaymentDetail3Fields.FieldByName("GLDESC").SetValue("sdsd", false); //GL description

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentDetail3Fields.FieldByName("IDACCT").SetValue("32423-343-454-454-45-454-454", false); ///account number

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentDetail3Fields.FieldByName("AMTDISTTC").SetValue("3400.00", false); //dist ammount

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentDetail3Fields.FieldByName("GLREF").SetValue("asdasD", false); //GL reference

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentDetail3.Insert();

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number

APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number

APPaymentDetail3.Read(false);
temp = APPaymentDetail3.Exists;
APPaymentDetail3.RecordCreate(0);

APPaymentDetail3Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number

APPaymentDetail3.Read(false);
APPaymentDetail3.Insert();

APPaymentHeaderFields.FieldByName("SWPRNTRMIT").SetValue("1", false); //check print required

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;

APPaymentBatch.Read(false);
APPaymentHeaderFields.FieldByName("CNTENTR").SetValue("0", false); //entry number
temp = APPaymentHeader.Exists;

APPaymentHeader.RecordCreate(0);

temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;
temp = APPaymentHeader.Exists;


Thanks in advance for any help
V3nd3tta
 
1. Get rid of every temp= line, that's just junk from the macro recording process.
2. Try a .Cancel before the .RecordCreate.
 
Hi,
I tried the cancel, and removed all the temp lines, but still i am getting the same exception.


 
Oh, I was looking at the wrong statement. Try:

APPaymentHeader.RecordCreate(1); or
APPaymentHeader.RecordCreate(True);

That's what works in VB.

 
Hi
Still no luck
The RecordCreate Method only takes something of the
enum ACCPAC.Advantage.ViewRecordCreate the only items in this enum is DelayKey,Insert,NoInsert....but none of these works....get an exception at runtime.

If I use the Boolean or 1 ..i get compiler error, telling me that I should use the enum,but when using 0, it compiles but still throws the exception.


Is there a way to get the errorcodes from the errorhandler,because on the inserts when i stepped the Macro it gave me errors with descriptions if any of my data was wrong

thanks
 
Change
Code:
APPaymentHeader.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);

to
Code:
APPaymentHeader.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.NoInsert);
 
I have tried both, still the same exception....aaarrrggghhhhhhhh
 
I would get everything working in a VBA macro first, then venture out to C.
Look at how the recorded error handler is done in VBA as well.
 
That is the real thing bothering me in VBA the thing works without errors....I posted here cause i thought, maby , hopefully somebody will tell me it is impossible, because I know it is possible , just can't get it to work.... : -<

Is there a real difference in doing this in vb.net and C# ? Otherwise I am considering trying doing it in vb.net then I will just call that dll from me c# side......
 
Here is a snippet to create a misc AP payment.

Code:
Dim DBLink As AccpacCOMAPI.AccpacDBLink
Dim APbatch As AccpacCOMAPI.AccpacView
Dim APheader As AccpacCOMAPI.AccpacView
Dim APdetail1 As AccpacCOMAPI.AccpacView
Dim APdetail2 As AccpacCOMAPI.AccpacView
Dim APdetail3 As AccpacCOMAPI.AccpacView
Dim APdetail4 As AccpacCOMAPI.AccpacView

Set DBLink = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
DBLink.OpenView "AP0030", APbatch
DBLink.OpenView "AP0031", APheader
DBLink.OpenView "AP0033", APdetail1
DBLink.OpenView "AP0034", APdetail2
DBLink.OpenView "AP0032", APdetail3
DBLink.OpenView "AP0406", APdetail4

APbatch.Compose Array(APheader)
APheader.Compose Array(APbatch, APdetail3, APdetail1, APdetail4)
APdetail1.Compose Array(APheader, APdetail2, Nothing)
APdetail2.Compose Array(APdetail1)
APdetail3.Compose Array(APheader)
APdetail4.Compose Array(APheader)


APbatch.Fields("PAYMTYPE").PutWithoutVerification ("PY")       ' Batch Selector
APbatch.Fields("CNTBTCH").PutWithoutVerification ("0")         ' Batch Number
APbatch.RecordCreate 1
APbatch.Fields("BATCHDESC").PutWithoutVerification ("Batch description")   ' Description
APbatch.Fields("DATEBTCH").Value = DateSerial(2008, 7, 1)      ' Batch Date
APbatch.Fields("IDBANK").Value = "SEATAC"                      ' Bank Code
APbatch.Update

APheader.RecordCreate 0
APheader.Fields("TEXTRMIT").Value = "Entry description"        ' Entry Description
APheader.Fields("RMITTYPE").Value = "4"                        ' Payment Trans. Type
APheader.Fields("PROCESSCMD").PutWithoutVerification ("0")     ' Process Command Code
APheader.Process
APheader.Fields("IDVEND").Value = "1200"                       ' Vendor Number
APheader.Fields("PROCESSCMD").PutWithoutVerification ("0")     ' Process Command Code
APheader.Process
APheader.Fields("SWPRNTRMIT").Value = "0"                      ' Check Print Required
APheader.Fields("IDRMIT").Value = "000000123456"               ' Check Number
APheader.Fields("TXTRMITREF").Value = "Reference"              ' Entry Reference
APheader.Fields("IDINVCMTCH").Value = "987654321"                 ' Matching Document Number

APdetail3.RecordCreate 0
APdetail3.Fields("GLDESC").Value = "Detail description"        ' G/L Description
APdetail3.Fields("IDACCT").Value = "9999"                      ' Account Number
APdetail3.Fields("AMTDISTTC").Value = "123.450"                ' Dist. Amount
APdetail3.Insert

APheader.Insert
 
I use VB6 as well if I really have to compile something, otherwise 99% of what I do is VBA.
 
Actually you only need one APheader.Process after the vendor number, the first one can come out out, as well as the line before it.
 
Thanks for all the help. I looked at the thing again , and compared it word by word with my Purchase orders that is working...the problem was not with anything but meself being a n00b....

I used the Accpac.Advantage.dll for version 5.3 and not 5.4....what a way to waste a week.....rofl....

me going to kick meself now..
cheers....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top