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

Can not insert AP invoice

Status
Not open for further replies.

NewCCTech

Technical User
Feb 18, 2010
65
CA
Hi everyone,

I am working on a program to create AP invoices in ACCPAC 54A with .net and SQL server 2008 developer edition. I got the following error when trying to insert a detail---System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.at AccpacCOMAPI.AccpacViewClass.Insert(). Can anyone give me suggestion and help me out here?

Thanks!
 
How to copy the rvSpy log? seems it does not allow to copy, please let me know and I will post it.

Yes, we have terms setup in AP.

Thanks!
 
Go to Options, Output... and you can tell rvSpy to log to a file.
 
You can save the RVSpy to a log file.
Whatever you do... don't post the whole frigging rvspy log file here, they are huge and difficult to read.
Typical steps for trouble shooting with the rvspy is to search from the bottom of the file for ERROR. Not every ERROR is an error, you need to filter through the stuff.
 
Hi All,

I have checked both my code with RvSpy, no problem at all, it is the same process on rvSpy as when create a AP batch manualy in Accpac.

My OS is 64 bit, would it be a matter? becuase I saw this post about Accpac.Advantage.Dll not working on 64 bit OS


Thanks for helps!
 
It looks like you're using the ComAPI.

I'm running Vista Home Premium x64 and have no problems.

I have checked both my code with RvSpy, no problem at all, it is the same process on rvSpy as when create a AP batch manualy in Accpac.

So do you have the problem when you create the batch manually?

Code:
      //Insert data
        APINVOICE1batch.Browse("(BTCHSTTS = 1)", true);
        temp = APINVOICE1batch.Exists;

        //insert a new Batch
        if (temp == false)
        {
            APINVOICE1batch.Init();
            APINVOICE1batch.Read();

That code looks wrong. You've asked Accpac to look for an open batch but don't call .Fetch. Then you're asking Accpac if your Batch view is pointing to an existing batch. If it is not on an existing batch then you start to create a batch.

Adjust your code so that it is closer to what Ettienne showed in his example. If you always want to create a new batch then get rid of the browse and create the new batch.

Also - this line:
Code:
pSession.Init("", "AP", "AP2100", VERSION);

should be:
Code:
pSession.Init("", "XY", "XY0001", VERSION);

And I'm assuming that VERSION is set to match your system manager version.

And we'll need to see the changes you've made to your code.
 
Hi DjangMan,

Thanks for your reply.

I am able to insert batch every time when I run my program. It threw exception at line

APINVOICE1header.Fields.get_FieldByName("IDVEND").set_Value(ref szBuffer);

the StackTrace message said that "Method (referring to set_Value()) may only be called on a Type for which Type.IsGenericParameter is true." and I saw IsGenericParameter was false.

Any idea on what was wrong? Thanks a lot!

Below is my code.



APINVOICE1batch.Browse("((BTCHSTTS = 1) OR (BTCHSTTS = 7))", true);
bool temp = APINVOICE1batch.Exists;
APINVOICE1batch.RecordClear();
APINVOICE1batch.RecordGenerate(true);
APINVOICE1batch.Read();

szBuffer = "Batch Insert --" + DateTime.Now.ToShortDateString();
APINVOICE1batch.Fields.get_FieldByName("BTCHDESC").set_Value(ref szBuffer);
APINVOICE1batch.Update();
//Header
APINVOICE1header.RecordClear();
APINVOICE1header.RecordGenerate(false);
APINVOICE1detail1.Cancel();
szBuffer = "169100";
APINVOICE1header.Fields.get_FieldByName("IDVEND").set_Value(ref szBuffer);
szBuffer = "4";
APINVOICE1header.Fields.get_FieldByName("PROCESSCMD").set_Value(ref szBuffer);
APINVOICE1header.Process();
szBuffer="222555555";
APINVOICE1header.Fields.get_FieldByName("IDINVC").set_Value(ref szBuffer);
szBuffer="800.00";
APINVOICE1header.Fields.get_FieldByName("AMTGROSTOT").set_Value(ref szBuffer);
//Detail
APINVOICE1detail1.RecordGenerate(false);
szBuffer="AMT";
APINVOICE1detail1.Fields.get_FieldByName("TEXTDESC").set_Value(ref szBuffer);
szBuffer="750";
APINVOICE1detail1.Fields.get_FieldByName("AMTDIST").set_Value(ref szBuffer);
APINVOICE1detail1.Insert();
szBuffer="-1";
APINVOICE1detail1.Fields.get_FieldByName("CNTLINE").PutWithoutVerification(ref szBuffer);
APINVOICE1detail1.Read();

APINVOICE1detail1.RecordGenerate(false);
szBuffer = "0";
APINVOICE1detail1.Fields.get_FieldByName("PROCESSCMD").set_Value(ref szBuffer);
APINVOICE1detail1.Process();
szBuffer="G";
APINVOICE1detail1.Fields.get_FieldByName("IDDIST").set_Value(ref szBuffer);
szBuffer="50";
APINVOICE1detail1.Fields.get_FieldByName("AMTDIST").set_Value(ref szBuffer);
APINVOICE1detail1.Insert();
APINVOICE1detail1.Browse("",true);

szBuffer="-2";
APINVOICE1detail1.Fields.get_FieldByName("CNTLINE").PutWithoutVerification(ref szBuffer);
APINVOICE1detail1.Read();

APINVOICE1header.Insert();

APINVOICE1batch.Update();
 
Hello,

Thanks for everyone's help!

Just want to share with you that I am able to insert AP invoices now.

Thanks again.
 
Hi DjangMan,

I switched to ACCPAC Advantage finally and
I used UPDATE() method to push the first detail record, then all the other detail records imported by using the following procedure
APINVOICE1detail1.Fields.FieldByName("CNTLINE").SetValue(lineNum, false);
APINVOICE1detail1.Read(false); APINVOICE1detail1.RecordClear(); APINVOICE1detail1.RecordGenerate(false);
APINVOICE1detail1.Fields.FieldByName("PROCESSCMD").SetValue("0", false);
APINVOICE1detail1.Process();
APINVOICE1detail1.Fields.FieldByName("IDDIST").SetValue(GSTDistCode, false);
APINVOICE1detail1.Fields.FieldByName("AMTDIST").SetValue(sGST, false);
APINVOICE1detail1.Insert();

then Header Inserted, Batch Updated

then a whole batch created

but I have not figured it out why so far. Will let you know once I know why.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top