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!

VB.NET ComAPI Create PO

Status
Not open for further replies.

badmotorvision

Programmer
Oct 15, 2009
22
US
Ok, Here is my code (From Macro after .net massaging)

The first place it pukes is the

POPOR1headerFields.Item("STCODE").Value = "104"
second place it pukes is the
POPOR1detail1.Insert()

This is straight from the macro what gives?
I dont understand



Dim Session As New AccpacCOMAPI.AccpacSession
Dim company, UserID, Password As String
company = Accpac_Interface.My.Settings.Company
UserID = My.Settings.UserID
Password = My.Settings.Password
Session.Init("", "XX", "XX1000", "55A")
Session.Open(UserID, Password, company, DateTime.Today, 0, "False")
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = Session.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
mDBLinkSysRW = Session.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_SYSTEM, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
Dim temp As Boolean
Dim POPOR1header As AccpacCOMAPI.AccpacView
Dim POPOR1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0620", POPOR1header)
POPOR1headerFields = POPOR1header.Fields

Dim POPOR1detail1 As AccpacCOMAPI.AccpacView
Dim POPOR1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0630", POPOR1detail1)
POPOR1detail1Fields = POPOR1detail1.Fields

Dim POPOR1detail2 As AccpacCOMAPI.AccpacView
Dim POPOR1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0610", POPOR1detail2)
POPOR1detail2Fields = POPOR1detail2.Fields

Dim POPOR1detail3 As AccpacCOMAPI.AccpacView
Dim POPOR1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0632", POPOR1detail3)
POPOR1detail3Fields = POPOR1detail3.Fields

Dim POPOR1detail4 As AccpacCOMAPI.AccpacView
Dim POPOR1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0619", POPOR1detail4)
POPOR1detail4Fields = POPOR1detail4.Fields

Dim POPOR1detail5 As AccpacCOMAPI.AccpacView
Dim POPOR1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0623", POPOR1detail5)
POPOR1detail5Fields = POPOR1detail5.Fields

Dim POPOR1detail6 As AccpacCOMAPI.AccpacView
Dim POPOR1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("PO0633", POPOR1detail6)
POPOR1detail6Fields = POPOR1detail6.Fields

POPOR1header.Compose(New AccpacCOMAPI.AccpacView() {POPOR1detail2, POPOR1detail1, POPOR1detail3, POPOR1detail4, POPOR1detail5})
POPOR1detail1.Compose(New AccpacCOMAPI.AccpacView() {POPOR1header, POPOR1detail2, POPOR1detail4, Nothing, Nothing, POPOR1detail6})
POPOR1detail2.Compose(New AccpacCOMAPI.AccpacView() {POPOR1header, POPOR1detail1})
POPOR1detail3.Compose(New AccpacCOMAPI.AccpacView() {POPOR1header, POPOR1detail4})
POPOR1detail4.Compose(New AccpacCOMAPI.AccpacView() {POPOR1header, POPOR1detail2, POPOR1detail1, POPOR1detail3})
POPOR1detail5.Compose(New AccpacCOMAPI.AccpacView() {POPOR1header})
POPOR1detail6.Compose(New AccpacCOMAPI.AccpacView() {POPOR1detail1})

POPOR1header.Order = 1
POPOR1header.Order = 0

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

temp = POPOR1header.Exists
POPOR1header.Init()
POPOR1header.Order = 1
temp = POPOR1detail1.Exists
POPOR1detail1.RecordClear()
temp = POPOR1detail3.Exists
POPOR1detail3.Init()
temp = POPOR1detail2.Exists
POPOR1detail2.Init()
POPOR1headerFields.Item("PONUMBER").Value = "MIKEPOTEST5" ' Purchase Order Number
temp = POPOR1header.Exists
POPOR1headerFields.Item("VDCODE").Value = "4IM001" ' Vendor
POPOR1headerFields.Item("TEMPLATE").Value = "ACTIVE" ' Template Code
POPOR1detail4Fields.Item("TEMPLATE").Value = "ACTIVE" ' Template Code
POPOR1detail4Fields.Item("FUNCTION").Value = "5" ' Function
POPOR1detail4.Process()
Try
'POPOR1headerFields.Item("STCODE").PutWithoutVerification("104") ' Ship-To Location
POPOR1headerFields.Item("STCODE").Value = "104" ' Ship-To Location
Catch ex As Exception

End Try
Try
'POPOR1headerFields.FieldByName("STCODE").PutWithoutVerification("104")
Catch ex As Exception

End Try

POPOR1headerFields.Item("DESCRIPTIO").Value = "desc" ' Description
POPOR1headerFields.Item("REFERENCE").Value = "ref" ' Reference

temp = POPOR1detail1.Exists
POPOR1detail1.RecordClear()
temp = POPOR1detail1.Exists
POPOR1detail1.RecordCreate(0)

POPOR1detail1Fields.Item("ITEMNO").Value = "ASD" ' Item Number
POPOR1detail1Fields.Item("ITEMDESC").Value = "asdf" ' Item Description
POPOR1detail1Fields.Item("OQORDERED").Value = "1.0000" ' Quantity Ordered
POPOR1detail1Fields.Item("UNITCOST").Value = "12.000000" ' Unit Cost

POPOR1detail1.Insert()

POPOR1detail1Fields.Item("PORLREV").PutWithoutVerification("-1") ' Line Number

POPOR1detail1.Read()
POPOR1detail4Fields.Item("FUNCTION").PutWithoutVerification("8") ' Function
POPOR1detail4.Process()
temp = POPOR1header.Exists
POPOR1header.Insert()
temp = POPOR1header.Exists
POPOR1header.Init()
POPOR1header.Order = 0

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

temp = POPOR1header.Exists
POPOR1header.Init()
POPOR1header.Order = 1
temp = POPOR1detail1.Exists
POPOR1detail1.RecordClear()
temp = POPOR1detail3.Exists
POPOR1detail3.Init()
temp = POPOR1detail2.Exists
POPOR1detail2.Init()


 
Iterate through Sessions.Errors and see if Accpac is telling you what the problem is.
 
Thanks for the tip on the session.errors
I found the problem. Some one created 2 test companies.
I was connecting to the wrong one so the STCODE i was putting in was invalid.
 
Next, delete all the "temp =" lines, that's just noise from the recording.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top