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

Error HRESULT E_FAIL on creating PO

Status
Not open for further replies.

dichetdi

Programmer
Aug 19, 2002
13
US
Hello all,

Can somebody please point out what I am doing wrong with the below code. Why am I getting the error "Error HRESULT E_FAIL has been returned from a call to a COM component." when I hit that line "POPOR1detail5.Update()" when trying to create a PO in Accpac 6.0

Code:
POPOR1header.Order = 1
            POPOR1header.Order = 0

            POPOR1headerFields.FieldByName("PORHSEQ").PutWithoutVerification("0")            ' Purchase Order Sequence Key

            POPOR1header.Init()
            POPOR1header.Order = 1
            temp = POPOR1detail1.Exists
            POPOR1detail1.RecordClear()
            POPOR1detail3.Init()
            POPOR1detail2.Init()
            POPOR1headerFields.FieldByName("VDCODE").Value = "200048"                         ' Vendor

            POPOR1headerFields.FieldByName("PROCESSCMD").PutWithoutVerification("1")         ' Command

            POPOR1header.Process()

            ''
            POPOR1detail5Fields.FieldByName("OPTFIELD").PutWithoutVerification("ORDERTAKEN")   ' Optional Field
            POPOR1detail5.Read()

            POPOR1detail5Fields.FieldByName("SWSET").Value = "1"                              ' Value Set

            temp = POPOR1detail5.Exists

            POPOR1detail5Fields.FieldByName("VALIFTEXT").Value = "00"                         ' Text Value

            POPOR1detail5.Update() '<-------THIS IS WHERE I GET THE ERROR

I've converted the vba code to C# and VB and it still throw the same error at the same line..
Thank you.
 
You can't update something that hasn't been inserted first. And get rid of the "temp =" lines.
 
So are you saying I should do my inserts like line numbers, header first before I update? Also, does the order of the insert matters?

POPOR1detail1.Insert()
POPOR1header.Insert()
POPOR1detail5.Update()
 
Yes, that's how I started. I recorded a bunch of macros and study the what it does. After that I attempted to convert the macro to .NET. The recorded macro runs fine in Accpac for creating a PO in the same order. But converting the vba to VB in the exact order it gave me that error. So that's why I am confuse as in why the update happens before the insert in Accpac but not .NET.
 
Sorry, I never use .Net, there's no reason to. VB and VBA is good enough.
 
Oh, that's cool. But from your experience, why would the recorded macro ran fine in Accpac but converted version in the same order error out because of the update before insert? Now I am not sure where and which insert to run first before the update. If I convert vba to VB6. I am guessing the same problem would occur.
 
Cool. First time converting VBA to anyting and from Accpac does not help either. I figured out the problem by postponing the update. Thank you for your help and input. Greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top