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!

Sage 300 ERP Order Entry Macro in vb.net - Help need, bit urgent.. please...

Status
Not open for further replies.

sarojaramkumar

Technical User
Nov 15, 2015
32
IN
Dear Team,

I have been assigned a task to convert macro into vb.net coding..for OE Order Entry screen, Thanks for Google and forum, but i got stuck at one place... System throws error at .process, .insert, .update, Please guide me... I need to submit this project by tomorrow Monday.

Here below is my code:

Dim mSession As New AccpacCOMAPI.AccpacSession
mSession = CreateObject("Accpac.Session")
mSession.Init("", "XY", "XY1000", "63A")

mSession.Open("ADMIN", "ADMIN", "SAMLTD", Now.Date, 0, "")

Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = mSession.OpenDBLink(1, 0)

Dim OEORD1header As AccpacCOMAPI.AccpacView
Dim OEORD1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0520", OEORD1header)
OEORD1headerFields = OEORD1header.Fields

Dim OEORD1detail1 As AccpacCOMAPI.AccpacView
Dim OEORD1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0500", OEORD1detail1)
OEORD1detail1Fields = OEORD1detail1.Fields

Dim OEORD1detail2 As AccpacCOMAPI.AccpacView
Dim OEORD1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0740", OEORD1detail2)
OEORD1detail2Fields = OEORD1detail2.Fields

Dim OEORD1detail9 As AccpacCOMAPI.AccpacView
Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0502", OEORD1detail9)
OEORD1detail9Fields = OEORD1detail9.Fields

'--------------- ram recorded macro start
Dim OEORD1detail3 As AccpacCOMAPI.AccpacView
Dim OEORD1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0180", OEORD1detail3)
OEORD1detail3Fields = OEORD1detail3.Fields

Dim OEORD1detail4 As AccpacCOMAPI.AccpacView
Dim OEORD1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0526", OEORD1detail4)
OEORD1detail4Fields = OEORD1detail4.Fields

Dim OEORD1detail5 As AccpacCOMAPI.AccpacView
Dim OEORD1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0522", OEORD1detail5)
OEORD1detail5Fields = OEORD1detail5.Fields

Dim OEORD1detail6 As AccpacCOMAPI.AccpacView
Dim OEORD1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0508", OEORD1detail6)
OEORD1detail6Fields = OEORD1detail6.Fields

Dim OEORD1detail7 As AccpacCOMAPI.AccpacView
Dim OEORD1detail7Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0507", OEORD1detail7)
OEORD1detail7Fields = OEORD1detail7.Fields

Dim OEORD1detail8 As AccpacCOMAPI.AccpacView
Dim OEORD1detail8Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0501", OEORD1detail8)
OEORD1detail8Fields = OEORD1detail8.Fields

' Dim OEORD1detail9 As AccpacCOMAPI.AccpacView
' Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields
'mDBLinkCmpRW.OpenView("OE0502", OEORD1detail9)
'OEORD1detail9Fields = OEORD1detail9.Fields

Dim OEORD1detail10 As AccpacCOMAPI.AccpacView
Dim OEORD1detail10Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0504", OEORD1detail10)
OEORD1detail10Fields = OEORD1detail10.Fields

Dim OEORD1detail11 As AccpacCOMAPI.AccpacView
Dim OEORD1detail11Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0506", OEORD1detail11)
OEORD1detail11Fields = OEORD1detail11.Fields

Dim OEORD1detail12 As AccpacCOMAPI.AccpacView
Dim OEORD1detail12Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0503", OEORD1detail12)
OEORD1detail12Fields = OEORD1detail12.Fields

'---------------------------------- ram recorded macro end

'----------------- ram composing start
'OEORD1header.Compose Array(OEORD1detail1, Nothing, OEORD1detail3, OEORD1detail2, OEORD1detail4, OEORD1detail5) ' macro coding

Dim mOEORD1header(6) As AccpacCOMAPI.AccpacView
mOEORD1header(0) = OEORD1detail1
mOEORD1header(1) = Nothing
mOEORD1header(2) = OEORD1detail3
mOEORD1header(3) = OEORD1detail2
mOEORD1header(4) = OEORD1detail4
mOEORD1header(5) = OEORD1detail5
OEORD1header.Compose(mOEORD1header)

'OEORD1detail1.Compose Array(OEORD1header, OEORD1detail8, OEORD1detail12, OEORD1detail9, OEORD1detail6, OEORD1detail7) ' macro coding

Dim mOEORD1detail1(6) As AccpacCOMAPI.AccpacView
mOEORD1detail1(0) = OEORD1header
mOEORD1detail1(1) = OEORD1detail8
mOEORD1detail1(2) = OEORD1detail12
mOEORD1detail1(3) = OEORD1detail9
mOEORD1detail1(4) = OEORD1detail6
mOEORD1detail1(5) = OEORD1detail7
OEORD1detail1.Compose(mOEORD1detail1)

'OEORD1detail2.Compose Array(OEORD1header) ' macro coding
Dim mOEORD1detail2(1) As AccpacCOMAPI.AccpacView
mOEORD1detail2(0) = OEORD1header
OEORD1detail2.Compose(mOEORD1detail2)

'OEORD1detail3.Compose Array(OEORD1header, OEORD1detail1) 'macro coding
Dim mOEORD1detail3(2) As AccpacCOMAPI.AccpacView
mOEORD1detail3(0) = OEORD1header
mOEORD1detail3(1) = OEORD1detail1
OEORD1detail3.Compose(mOEORD1detail3)

'OEORD1detail4.Compose Array(OEORD1header) 'macro coding
Dim mOEORD1detail4(1) As AccpacCOMAPI.AccpacView
mOEORD1detail2(0) = OEORD1header
OEORD1detail2.Compose(mOEORD1detail4)

'OEORD1detail5.Compose Array(OEORD1header) 'macro coding
Dim mOEORD1detail5(1) As AccpacCOMAPI.AccpacView
mOEORD1detail5(0) = OEORD1header
OEORD1detail2.Compose(mOEORD1detail5)

'OEORD1detail6.Compose Array(OEORD1detail1) ' macro coding
Dim mOEORD1detail6(1) As AccpacCOMAPI.AccpacView
mOEORD1detail6(0) = OEORD1header
OEORD1detail6.Compose(mOEORD1detail6)

'OEORD1detail7.Compose Array(OEORD1detail1) ' macro coding
Dim mOEORD1detail7(1) As AccpacCOMAPI.AccpacView
mOEORD1detail7(1) = OEORD1detail1
OEORD1detail7.Compose(mOEORD1detail7)

'OEORD1detail8.Compose Array(OEORD1detail1) 'macro coding
Dim mOEORD1detail8(1) As AccpacCOMAPI.AccpacView
mOEORD1detail8(0) = OEORD1detail1
OEORD1detail8.Compose(mOEORD1detail8)

'OEORD1detail9.Compose Array(OEORD1detail1, OEORD1detail10, OEORD1detail11) ' macro coding
Dim mOEORD1detail9(3) As AccpacCOMAPI.AccpacView
mOEORD1detail9(0) = OEORD1detail1
mOEORD1detail9(1) = OEORD1detail10
mOEORD1detail9(2) = OEORD1detail11
OEORD1detail9.Compose(mOEORD1detail9)

'OEORD1detail10.Compose Array(OEORD1detail9) 'macro coding
Dim mOEORD1detail10(1) As AccpacCOMAPI.AccpacView
mOEORD1detail10(0) = OEORD1detail9
OEORD1detail10.Compose(mOEORD1detail10)

'OEORD1detail11.Compose Array(OEORD1detail9) 'macro coding
Dim mOEORD1detail11(1) As AccpacCOMAPI.AccpacView
mOEORD1detail11(0) = OEORD1detail9
OEORD1detail11.Compose(mOEORD1detail11)


'OEORD1detail12.Compose Array(OEORD1detail1) 'macro coding
Dim mOEORD1detail12(1) As AccpacCOMAPI.AccpacView
mOEORD1detail12(0) = OEORD1detail1
OEORD1detail12.Compose(mOEORD1detail12)


'----------------------------------- ram composing end

'-------------------------------------------------------------------------------------------- ram code macro conversion
OEORD1headerFields.FieldByName("DRIVENBYUI").Value = "1" ' Driven by UI
OEORD1detail1Fields.FieldByName("DRIVENBYUI").Value = "1" ' Driven by UI
OEORD1header.Cancel()
OEORD1header.Cancel()
OEORD1header.Init()
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1header.Cancel()
OEORD1header.Init()
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1headerFields.FieldByName("CUSTOMER").Value = "1200" ' Customer Number
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1headerFields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process OIP Command
OEORD1header.Init()
OEORD1header.Process()

OEORD1headerFields.FieldByName("PONUMBER").Value = "PONUMBER" ' Purchase Order Number

'OEORD1headerFields.FieldByName("SHIPTO").Value = "HOME" ' Ship-To Location Code
OEORD1headerFields.FieldByName("GOFCALCTAX").PutWithoutVerification("1") ' Perform Forced Tax Calculation
OEORD1header.Init()
'OEORD1header.Process()

OEORD1headerFields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process OIP Command

'OEORD1header.Process()

OEORD1headerFields.FieldByName("SHIPVIA").Value = "CCT" ' Ship-Via Code
OEORD1headerFields.FieldByName("SHIPTRACK").Value = "TRACKING NUMBER-001" ' Shipment Tracking Number
'temp = OEORD1detail1.Exists
'OEORD1detail1.RecordClear()
'temp = OEORD1detail1.Exists
'OEORD1detail1.RecordCreate(0)
OEORD1detail1.RecordGenerate(0)

OEORD1detail1Fields.FieldByName("ITEM").Value = "A1-103/0" ' Item
OEORD1detail1Fields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process Command


'OEORD1detail1.Process()

OEORD1detail1Fields.FieldByName("QTYORDERED").Value = "19.0000" ' Quantity Ordered
OEORD1detail1Fields.FieldByName("PRIUNTPRC").Value = "100.000000" ' Pricing Unit Price
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("COLOR") ' Optional Field
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("DANGEROUS") ' Optional Field
OEORD1detail8.Read()
OEORD1detail8Fields.FieldByName("VALIFBOOL").Value = "1"

' OEORD1detail8.Update()
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("EXTWARRANTY") ' Optional Field
OEORD1detail8.Read()

OEORD1detail8Fields.FieldByName("VALIFBOOL").Value = "1" ' Yes/No Value
'OEORD1detail8.Update()
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("GENDER") ' Optional Field
OEORD1detail8.Read()
OEORD1detail8Fields.FieldByName("SWSET").Value = "1" ' Value Set

'OEORD1detail8.Update()
OEORD1detail8.Browse("", 1)

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("SEASON") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("SIZEB") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("STYLE") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("STYLEDESC") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()
OEORD1detail8.Browse("", 0)
OEORD1detail8.Fetch()
OEORD1detail8.Read()
' OEORD1detail1.Init()

OEORD1detail1.Insert()
'--------
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-1") ' Line Number

OEORD1detail1.Read()
OEORD1headerFields.FieldByName("GOCALCTAX").PutWithoutVerification("1") ' Perform Tax Calculation

OEORD1headerFields.FieldByName("REFERENCE").PutWithoutVerification("REFERENCE") ' Order Reference
OEORD1headerFields.FieldByName("DESC").PutWithoutVerification("DESCRIPTION") ' Order Description

'OEORD1header.Process()
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-1") ' Line Number

OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-1") ' Line Number

OEORD1detail1.Read()
'temp = OEORD1detail1.Exists
OEORD1detail1.RecordCreate(0)

OEORD1detail1Fields.FieldByName("LINETYPE").Value = "2" ' Line Type

OEORD1detail1Fields.FieldByName("MISCCHARGE").Value = "HC" ' Miscellaneous Charges Code
OEORD1detail1Fields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process Command

'OEORD1detail1.Process()

OEORD1detail1Fields.FieldByName("EXTINVMISC").Value = "1000.000" ' Extended Amount
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-2") ' Line Number
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("COLOR") ' Optional Field
OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("GENDER") ' Optional Field
OEORD1detail8.Read()
OEORD1detail8Fields.FieldByName("SWSET").Value = "1" ' Value Set

'temp = OEORD1detail8.Exists

'OEORD1detail8.Update()
OEORD1detail8.Browse("", 1)

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("SEASON") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("SIZEB") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("STYLE") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()
OEORD1detail8.Browse("", 1)

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("STYLEDESC") ' Optional Field

OEORD1detail8.Read()

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

'temp = OEORD1detail8.Exists
'OEORD1detail8.Update()

OEORD1detail8Fields.FieldByName("OPTFIELD").PutWithoutVerification("WARRANTYPRD") ' Optional Field

OEORD1detail8.Read()
'OEORD1detail1.Insert()

OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-2") ' Line Number

OEORD1detail1.Read()
OEORD1headerFields.FieldByName("OECOMMAND").Value = "4" ' Process O/E Command
OEORD1header.Init()
'OEORD1header.Process()
'OEORD1header.Insert()
OEORD1header.Order = 1
OEORD1header.Read()
OEORD1header.Order = 0
OEORD1detail1Fields.FieldByName("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail9Fields.FieldByName("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number

OEORD1detail9Fields.FieldByName("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number

OEORD1detail9.Browse("", 1)
OEORD1detail9.Fetch()
OEORD1detail3Fields.FieldByName("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()

OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-2") ' Payment Number
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields.FieldByName("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()

OEORD1header.Post()
OEORD1detail1.Post()
'------------
mDBLinkCmpRW.Close()
mSession.Close()
End Sub







 
You have no error trapping/reporting. It's entirely possible that Sage is telling you what the error is.

 
@DjangMan: Thanks for your response,
I am sorry, i missed to mentioned what error sage is throwing:
here below the error i am getting in each and every .insert and .process lines of the above code:
Error HRESULT E_FAIL has been returned from a call to a COM component

Could you please help...

Thanks
Ram
 
That's the error code from VB.Net. The Accpac Session object has an error stack. Record a macro in Sage and you'll see the code. You'll have something like this:

Code:
        Dim idxError As Integer
        Dim OutString As String
        If Session.Errors.Count > 0 Then
            OutString = ""

            For idxError = 0 To Session.Errors.Count - 1
                OutString = OutString + Session.Errors.Item(idxError) & vbLf
            Next idxError
            Select Case MsgBox("Errors reported as follows:" & vbLf & OutString & vbLf & "Do you want to continue processing?", MsgBoxStyle.YesNo)
                Case vbYes : Resume Next
                Case vbNo : Exit Sub
            End Select
            Session.Errors.Clear()
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top