Hello,
System: MISYS 5.0 - Accpac Advantage series 5.2.
The manufacturing header is created but the materials and the routings are not copied in the MO.
Any help appreciated.
Public Function SaveMO(ByVal strCompany As String) As String
Dim Connection As New SqlConnection(Global.ConnStr)
Dim drItem As SqlDataReader
Dim strSQL As String
Dim command As New SqlCommand(strSQL, Connection)
Dim oSession As AccpacCOMAPI.AccpacSession
Dim AccpacDBLink As AccpacCOMAPI.AccpacDBLink
Dim sUsername As String
Dim sPassword As String
Dim iTransactionLevel As Integer
Dim SysLink As AccpacCOMAPI.AccpacDBLink
Dim intErrCount As Integer
Dim temp As String
Dim strID As String
Dim rc As tagViewReturnCode
Dim oFPUtils As New FPUtils
Connection.Open()
strSQL = "SELECT Manufacturing_Order_Headers.* FROM Manufacturing_Order_Headers "
strSQL &= "WHERE 1=1 "
command.CommandType = CommandType.Text
command.CommandText = strSQL
drItem = command.ExecuteReader()
'**********************************
' On établit la connection à Accpac
'**********************************
sUsername = oFPUtils.GetCompanyUsername(strCompany)
sPassword = oFPUtils.GetCompanyPassword(strCompany)
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
oSession = New AccpacCOMAPI.AccpacSession
Try
oSession.Init("", "SM", "SM0000", "52A")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function
Finally
End Try
Try
oSession.Open(sUsername, sPassword, strCompany, System.DateTime.Today, 0, "")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function
Finally
End Try
AccpacDBLink = oSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
Dim MIGLOB1 As AccpacCOMAPI.AccpacView
Dim MIGLOB1Fields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0008", MIGLOB1)
MIGLOB1Fields = MIGLOB1.Fields
MIGLOB1.Init()
MIGLOB1.Browse("", 1)
MIGLOB1.Fetch()
Dim MIMOHheader As AccpacCOMAPI.AccpacView
Dim MIMOHheaderArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHheaderFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0046", MIMOHheader)
MIMOHheaderFields = MIMOHheader.Fields
Dim MIMOHdetail As AccpacCOMAPI.AccpacView
Dim MIMOHdetailArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHdetailFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0047", MIMOHdetail)
MIMOHdetailFields = MIMOHdetail.Fields
Dim MIMORD As AccpacCOMAPI.AccpacView
Dim MIMORDArray(2) As AccpacCOMAPI.AccpacView
Dim MIMORDFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0065", MIMORD)
MIMORDFields = MIMORD.Fields
MIMOHheaderArray(0) = MIMOHdetail
MIMOHheaderArray(1) = MIMORD
MIMOHheader.Compose(MIMOHheaderArray)
MIMOHdetailArray(0) = MIMOHheader
MIMOHdetailArray(1) = Nothing
MIMOHdetail.Compose(MIMOHdetailArray)
MIMORDArray(0) = MIMOHheader
MIMORDArray(1) = Nothing
MIMORD.Compose(MIMORDArray)
Try
While drItem.Read()
MIMOHheader.Init()
MIMOHheaderFields.Item("WOHID").Value = drItem("WOHID") ' Order No.
MIMOHheaderFields.Item("ITEM").Value = drItem("ITEM") ' Assembly No.
MIMOHheaderFields.Item("DESCR").Value = drItem("DESCR") ' Description
MIMOHheaderFields.Item("LOC").Value = "LOC01" ' Location
MIMOHheaderFields.Item("STARTDATE").Value = Now().Date ' Start Date
MIMOHheaderFields.Item("ENDDATE").Value = Now().Date ' Completion Date
MIMOHheaderFields.Item("HDRTX1").Value = drItem("HDRTX1") ' ABC
MIMOHheaderFields.Item("HDRTX2").Value = drItem("HDRTX2") ' Couverture
MIMOHheaderFields.Item("ORDERQTY").Value = drItem("ORDERQTY") ' Required Quantity
MIMOHheaderFields.Item("CREATOR").Value = "SYSTEM"
MIMOHheaderFields.Item("RELEASDATE").Value = Now().Date
MIMOHheaderFields.Item("RELEASER").PutWithoutVerification("ADMIN") ' Released By
MIMOHheaderFields.Item("MOSTAT").Value = "1"
MIMOHheaderFields.Item("PRSTAT").Value = "4"
MIMOHheader.Post()
MIMOHheader.Process()
MIMOHheader.Insert()
rc = MIMOHheader.LastReturnCode
MIMOHdetail.Post()
MIMOHdetail.Process()
rc = MIMOHdetail.LastReturnCode
End While
Catch err As Exception
' Annuler la transaction
AccpacDBLink.TransactionRollback(iTransactionLevel)
intErrCount = oSession.Errors.Count
Dim j As Integer
For j = 0 To intErrCount - 1
SaveMO = "Erreur:" & oSession.Errors.Item(j)
Next
Finally
MIMOHdetail.Close()
MIMOHheader.Close()
MIMORD.Close()
MIGLOB1.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
oSession.Close()
command.Dispose()
drItem.Close()
Connection.Close()
End Try
End Function
System: MISYS 5.0 - Accpac Advantage series 5.2.
The manufacturing header is created but the materials and the routings are not copied in the MO.
Any help appreciated.
Public Function SaveMO(ByVal strCompany As String) As String
Dim Connection As New SqlConnection(Global.ConnStr)
Dim drItem As SqlDataReader
Dim strSQL As String
Dim command As New SqlCommand(strSQL, Connection)
Dim oSession As AccpacCOMAPI.AccpacSession
Dim AccpacDBLink As AccpacCOMAPI.AccpacDBLink
Dim sUsername As String
Dim sPassword As String
Dim iTransactionLevel As Integer
Dim SysLink As AccpacCOMAPI.AccpacDBLink
Dim intErrCount As Integer
Dim temp As String
Dim strID As String
Dim rc As tagViewReturnCode
Dim oFPUtils As New FPUtils
Connection.Open()
strSQL = "SELECT Manufacturing_Order_Headers.* FROM Manufacturing_Order_Headers "
strSQL &= "WHERE 1=1 "
command.CommandType = CommandType.Text
command.CommandText = strSQL
drItem = command.ExecuteReader()
'**********************************
' On établit la connection à Accpac
'**********************************
sUsername = oFPUtils.GetCompanyUsername(strCompany)
sPassword = oFPUtils.GetCompanyPassword(strCompany)
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
oSession = New AccpacCOMAPI.AccpacSession
Try
oSession.Init("", "SM", "SM0000", "52A")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function
Finally
End Try
Try
oSession.Open(sUsername, sPassword, strCompany, System.DateTime.Today, 0, "")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function
Finally
End Try
AccpacDBLink = oSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
Dim MIGLOB1 As AccpacCOMAPI.AccpacView
Dim MIGLOB1Fields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0008", MIGLOB1)
MIGLOB1Fields = MIGLOB1.Fields
MIGLOB1.Init()
MIGLOB1.Browse("", 1)
MIGLOB1.Fetch()
Dim MIMOHheader As AccpacCOMAPI.AccpacView
Dim MIMOHheaderArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHheaderFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0046", MIMOHheader)
MIMOHheaderFields = MIMOHheader.Fields
Dim MIMOHdetail As AccpacCOMAPI.AccpacView
Dim MIMOHdetailArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHdetailFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0047", MIMOHdetail)
MIMOHdetailFields = MIMOHdetail.Fields
Dim MIMORD As AccpacCOMAPI.AccpacView
Dim MIMORDArray(2) As AccpacCOMAPI.AccpacView
Dim MIMORDFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0065", MIMORD)
MIMORDFields = MIMORD.Fields
MIMOHheaderArray(0) = MIMOHdetail
MIMOHheaderArray(1) = MIMORD
MIMOHheader.Compose(MIMOHheaderArray)
MIMOHdetailArray(0) = MIMOHheader
MIMOHdetailArray(1) = Nothing
MIMOHdetail.Compose(MIMOHdetailArray)
MIMORDArray(0) = MIMOHheader
MIMORDArray(1) = Nothing
MIMORD.Compose(MIMORDArray)
Try
While drItem.Read()
MIMOHheader.Init()
MIMOHheaderFields.Item("WOHID").Value = drItem("WOHID") ' Order No.
MIMOHheaderFields.Item("ITEM").Value = drItem("ITEM") ' Assembly No.
MIMOHheaderFields.Item("DESCR").Value = drItem("DESCR") ' Description
MIMOHheaderFields.Item("LOC").Value = "LOC01" ' Location
MIMOHheaderFields.Item("STARTDATE").Value = Now().Date ' Start Date
MIMOHheaderFields.Item("ENDDATE").Value = Now().Date ' Completion Date
MIMOHheaderFields.Item("HDRTX1").Value = drItem("HDRTX1") ' ABC
MIMOHheaderFields.Item("HDRTX2").Value = drItem("HDRTX2") ' Couverture
MIMOHheaderFields.Item("ORDERQTY").Value = drItem("ORDERQTY") ' Required Quantity
MIMOHheaderFields.Item("CREATOR").Value = "SYSTEM"
MIMOHheaderFields.Item("RELEASDATE").Value = Now().Date
MIMOHheaderFields.Item("RELEASER").PutWithoutVerification("ADMIN") ' Released By
MIMOHheaderFields.Item("MOSTAT").Value = "1"
MIMOHheaderFields.Item("PRSTAT").Value = "4"
MIMOHheader.Post()
MIMOHheader.Process()
MIMOHheader.Insert()
rc = MIMOHheader.LastReturnCode
MIMOHdetail.Post()
MIMOHdetail.Process()
rc = MIMOHdetail.LastReturnCode
End While
Catch err As Exception
' Annuler la transaction
AccpacDBLink.TransactionRollback(iTransactionLevel)
intErrCount = oSession.Errors.Count
Dim j As Integer
For j = 0 To intErrCount - 1
SaveMO = "Erreur:" & oSession.Errors.Item(j)
Next
Finally
MIMOHdetail.Close()
MIMOHheader.Close()
MIMORD.Close()
MIGLOB1.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
oSession.Close()
command.Dispose()
drItem.Close()
Connection.Close()
End Try
End Function