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!

Incomplete macro when record PJC Material Usage

Status
Not open for further replies.

aan09

Programmer
Mar 21, 2018
29
ID
Please help,

I want to make macro of PJC Material Usage but when I record it the result was incomplete.

The result didn't show the definition of view, compose array, date, etc.

I didn't know where is the problem because when I recorded other module there was no problem with it.
 
Sorry - nevermind. You asked about Material Usage, not Cost Entry.
 
It's not a complicated set of views. You can probably record a time entry macro and duplicate the logic. You can also have a good look at the rvSpy .Compose calls but sometimes there's a lot of noise.
 
Thanks for your answer,

I had tried rvSpy but there's a lot of noise so I didn't know which one I must used.

Record tyme entry macro, you mean timecards entry or other function?
 
Yes - timecard entry. You should be able to look at the object models and the timecard entry macro to figure out the composition:

Material Usage
RotoID: PM0050
Table: PMMATH
Protocol: Header, Key auto generate
DLL:pMMATH
Compositions: 4
RotoID Tables Title
PM0051 PMMATD Material Usage Detail
PM0483 PMMATDS Material Usage Detail Serial Num
PM0484 PMMATDL Material Usage Detail Lot Number
PM0538 PMMATHO Material Usage Optional Field

Timecard
RotoID: PM0040
Table: PMTIMEH
Protocol: Header, Key auto generate
DLL:pMTIMEH
Compositions: 4
RotoID Tables Title
PM0041 PMTIMED Timecard Time Detail
PM0113 PMTIMEE Timecard Expense Detail
PM0115 PMTIMET Timecard Time Totals
PM0532 PMTIMHO Timecard Optional Field
 
Thanks DjangMan, I will try it.
 
Hi, DjangMan

I've successed to make PJC Material Usage Macro, but there is a problem when I converted it to vb.net. Usually there is no problem when insert header and detail in another function but in Material Usage I can insert header but I cannot insert the detail, please help.

PJC Material Usage Macro :

Sub MainSub()
'
' Sage 300 Macro file: D:\Data\Aan\Khaileena Project\MaterialRequest\Macro\mu12.AVB
' Recorded at: Fri May 11 22:10:21 2018
'

On Error GoTo ACCPACErrorHandler

' TODO: To increase efficiency, comment out any unused DB links.
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)

Dim temp As Boolean
Dim PMMAT1header As AccpacCOMAPI.AccpacView
Dim PMMAT1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0050", PMMAT1header
Set PMMAT1headerFields = PMMAT1header.Fields

Dim PMMAT1detail1 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0051", PMMAT1detail1
Set PMMAT1detail1Fields = PMMAT1detail1.Fields

Dim PMMAT1detail2 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0483", PMMAT1detail2
Set PMMAT1detail2Fields = PMMAT1detail2.Fields

Dim PMMAT1detail3 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0484", PMMAT1detail3
Set PMMAT1detail3Fields = PMMAT1detail3.Fields

Dim PMMAT1detail4 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0537", PMMAT1detail4
Set PMMAT1detail4Fields = PMMAT1detail4.Fields

Dim PMMAT1detail5 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0538", PMMAT1detail5
Set PMMAT1detail5Fields = PMMAT1detail5.Fields

Dim PMMAT1detail6 As AccpacCOMAPI.AccpacView
Dim PMMAT1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0539", PMMAT1detail6
Set PMMAT1detail6Fields = PMMAT1detail6.Fields

PMMAT1header.Compose Array(PMMAT1detail1, PMMAT1detail2, PMMAT1detail3, PMMAT1detail5)

PMMAT1detail1.Compose Array(PMMAT1header, PMMAT1detail2, PMMAT1detail3)

PMMAT1detail2.Compose Array(PMMAT1detail1, PMMAT1header)

PMMAT1detail3.Compose Array(PMMAT1detail1, PMMAT1header)

PMMAT1detail4.Compose Array(PMMAT1detail1)

PMMAT1detail5.Compose Array(PMMAT1header)


PMMAT1header.Order = 1
PMMAT1header.Order = 0
PMMAT1header.Init
temp = PMMAT1header.Exists
PMMAT1header.Order = 1

PMMAT1headerFields("MATERIALNO").Value = "TESTMU2" ' Material Usage Number

temp = PMMAT1header.Exists
PMMAT1header.Order = 0

PMMAT1headerFields("SEQ").Value = "0" ' Sequence

PMMAT1header.Init
PMMAT1header.Order = 1

PMMAT1headerFields("MATERIALNO").Value = "TESTMU1" ' Material Usage Number
temp = PMMAT1header.Exists

PMMAT1headerFields("TRANSDATE").Value = DateSerial(2018, 5, 9) ' Transaction Date
PMMAT1headerFields("DESC").Value = "jajal input" ' Description
PMMAT1headerFields("REFERENCE").Value = "ok" ' Reference

temp = PMMAT1detail1.Exists
PMMAT1detail1.RecordClear
temp = PMMAT1detail1.Exists
PMMAT1detail1.RecordCreate 0

PMMAT1detail1Fields("FMTCONTNO").Value = "EC0001-B0003" ' Contract

PMMAT1detail1Fields("PROJECT").Value = "EFS" ' Project

PMMAT1detail1Fields("CATEGORY").Value = "4300" ' Category

PMMAT1detail1Fields("RESOURCE").Value = "CAS006" ' Item Number
PMMAT1detail1Fields("LOCATION").Value = "JKT" ' Location
PMMAT1detail1Fields("QUANTITY").Value = "2.00000" ' Quantity

PMMAT1detail1.Insert
temp = PMMAT1header.Exists
PMMAT1detail1Fields("LINENO").PutWithoutVerification ("-1") ' Line Number


PMMAT1detail1.Read
PMMAT1header.Insert

Exit Sub

ACCPACErrorHandler:
Dim lCount As Long
Dim lIndex As Long

If Errors Is Nothing Then
MsgBox Err.Description
Else
lCount = Errors.Count

If lCount = 0 Then
MsgBox Err.Description
Else
For lIndex = 0 To lCount - 1
MsgBox Errors.Item(lIndex)
Next
Errors.Clear
End If
Resume Next

End If

End Sub


My vb.net PJC Material Usage code :

Dim session As ACCPAC.Advantage.Session
Dim mDBLinkCmpRW As ACCPAC.Advantage.DBLink

session = New ACCPAC.Advantage.Session()
session.Init("", "XX", "XX1000", "64A")
session.Open("ADMIN", "ADMIN", "TKTIND", DateTime.Today, 0)
mDBLinkCmpRW = session.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite)

Dim PMMAT1header As ACCPAC.Advantage.View
PMMAT1header = mDBLinkCmpRW.OpenView("PM0050")

Dim PMMAT1detail1 As ACCPAC.Advantage.View
PMMAT1detail1 = mDBLinkCmpRW.OpenView("PM0051")

Dim PMMAT1detail2 As ACCPAC.Advantage.View
PMMAT1detail2 = mDBLinkCmpRW.OpenView("PM0483")

Dim PMMAT1detail3 As ACCPAC.Advantage.View
PMMAT1detail3 = mDBLinkCmpRW.OpenView("PM0484")

Dim PMMAT1detail4 As ACCPAC.Advantage.View
PMMAT1detail4 = mDBLinkCmpRW.OpenView("PM0537")

Dim PMMAT1detail5 As ACCPAC.Advantage.View
PMMAT1detail5 = mDBLinkCmpRW.OpenView("PM0538")

PMMAT1header.Compose({PMMAT1detail1, PMMAT1detail2, PMMAT1detail3, PMMAT1detail5})
PMMAT1detail1.Compose({PMMAT1header, PMMAT1detail2, PMMAT1detail3})
PMMAT1detail2.Compose({PMMAT1detail1, PMMAT1header})
PMMAT1detail3.Compose({PMMAT1detail1, PMMAT1header})
PMMAT1detail4.Compose({PMMAT1detail1})
PMMAT1detail5.Compose({PMMAT1header})

PMMAT1header.Fields.FieldByName("SEQ").SetValue("0", False) ' Sequence
PMMAT1header.Init()
PMMAT1header.Fields.FieldByName("MATERIALNO").SetValue("TESTMU1", False) ' Material Usage Number
PMMAT1header.Fields.FieldByName("TRANSDATE").SetValue("2018/05/09", False) ' Transaction Date
PMMAT1header.Fields.FieldByName("DESC").SetValue("jajal input", False) ' Description
PMMAT1header.Fields.FieldByName("REFERENCE").SetValue("ok", False)

PMMAT1detail1.RecordCreate(ViewRecordCreate.NoInsert)

PMMAT1detail1.Fields.FieldByName("FMTCONTNO").SetValue("EC0001-B0003", False) ' Contract
PMMAT1detail1.Fields.FieldByName("PROJECT").SetValue("EFS", False) ' Project
PMMAT1detail1.Fields.FieldByName("CATEGORY").SetValue("4300", False) ' Category
PMMAT1detail1.Fields.FieldByName("RESOURCE").SetValue("CAS013", False) ' Item Number
PMMAT1detail1.Fields.FieldByName("LOCATION").SetValue("JKT", False) ' Location
PMMAT1detail1.Fields.FieldByName("QUANTITY").SetValue("2", False) ' Quantity
PMMAT1detail1.Insert()

PMMAT1detail1.Fields.FieldByName("LINENO").SetValue("-1", False) ' Line Number
PMMAT1header.Insert()
 
What error is returned in Session.Errors after PMMAT1detail1.Insert()?

Sage 300 Whisperer
 
This the error when I run the program

error_Material_Usage_w9m9n5.jpg
 
You have to process through the session.error message stack. See your original code under "AccpacErrorHandler". That code needs to be converted to .Net and that's the code that should be in your try...catch around your code, above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top