I have to solve a macro that was made for Accpac 5.2 but it does not work now for Accpac 6.0. I think this is because the optional fields is presented different in 6.0. This macro charge an extra value to the total of the order but just to those items that have that optional field. Here I paste the code of the macro. Hope you can help me.
Dim WithEvents dsOEORDH As AccpacOE1100.ACCPACDSControl
Private Sub AccpacOE1100UICtrl1_OnUIAppClosed()
Unload OrderEntryFrm
End Sub
Private Sub AccpacOE1100UICtrl1_OnUIAppOpened()
Set dsOEORDH = AccpacOE1100UICtrl1.UIDSControls.item("adsOEORDH")
End Sub
Private Sub dsOEORDH_OnRecordChanging(ByVal eReason As tagEventReason, pStatus As tagEventStatus, ByVal pField As AccpacDataSrc.IAccpacDSField, ByVal pMultipleFields As AccpacDataSrc.IAccpacDSFields)
Dim item As String
Dim qtyShipped As Integer
Dim amount As Currency
Dim totalAmt As Currency
Dim response As VbMsgBoxResult
Dim dsOEORDD As AccpacOE1100.ACCPACDSControl
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Dim ICITEM As AccpacCOMAPI.AccpacView
If eReason = RSN_ADDNEW Or eReason = RSN_UPDATE Then
Set dsOEORDD = AccpacOE1100UICtrl1.UIDSControls.item("adsOEORDD")
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
dsOEORDD.GoTop
qtyShipped = 0
totalAmt = 0#
'Sum the cost of the miscellaneous fee
Do
qtyShipped = dsOEORDD.Fields("QTYSHIPPED").Value
mDBLinkCmpRW.OpenView "IC0310", ICITEM
item = dsOEORDD.Fields("UNFMTITEM").Value
ICITEM.Browse "ITEMNO= """ & item & """", True
ICITEM.Fetch
amount = ICITEM.Fields("OPTAMT").Value
totalAmt = totalAmt + amount * qtyShipped
lineNum = dsOEORDD.Fields("LINENUM").Value
'go to the next order detail line record
Loop While dsOEORDD.GoNext = True
'If the total cost of the miscellaneous fee is not 0.00 then add a detail line
If totalAmt <> 0# Then
dsOEORDD.Init
dsOEORDD.Fields("LINETYPE").Value = 2
dsOEORDD.Fields("MISCCHARGE").Value = "EHCHGE" ' Item
dsOEORDD.Fields("EXTINVMISC").Value = totalAmt ' Extended Amount
dsOEORDD.Fields("COMPLETE").PutWithoutVerification ("0")
dsOEORDD.Fields("LINENUM").PutWithoutVerification (lineNum)
End If
Set mDBLinkCmpRW = Nothing
Set dsOEORDD = Nothing
End If
End Sub
Dim WithEvents dsOEORDH As AccpacOE1100.ACCPACDSControl
Private Sub AccpacOE1100UICtrl1_OnUIAppClosed()
Unload OrderEntryFrm
End Sub
Private Sub AccpacOE1100UICtrl1_OnUIAppOpened()
Set dsOEORDH = AccpacOE1100UICtrl1.UIDSControls.item("adsOEORDH")
End Sub
Private Sub dsOEORDH_OnRecordChanging(ByVal eReason As tagEventReason, pStatus As tagEventStatus, ByVal pField As AccpacDataSrc.IAccpacDSField, ByVal pMultipleFields As AccpacDataSrc.IAccpacDSFields)
Dim item As String
Dim qtyShipped As Integer
Dim amount As Currency
Dim totalAmt As Currency
Dim response As VbMsgBoxResult
Dim dsOEORDD As AccpacOE1100.ACCPACDSControl
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Dim ICITEM As AccpacCOMAPI.AccpacView
If eReason = RSN_ADDNEW Or eReason = RSN_UPDATE Then
Set dsOEORDD = AccpacOE1100UICtrl1.UIDSControls.item("adsOEORDD")
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
dsOEORDD.GoTop
qtyShipped = 0
totalAmt = 0#
'Sum the cost of the miscellaneous fee
Do
qtyShipped = dsOEORDD.Fields("QTYSHIPPED").Value
mDBLinkCmpRW.OpenView "IC0310", ICITEM
item = dsOEORDD.Fields("UNFMTITEM").Value
ICITEM.Browse "ITEMNO= """ & item & """", True
ICITEM.Fetch
amount = ICITEM.Fields("OPTAMT").Value
totalAmt = totalAmt + amount * qtyShipped
lineNum = dsOEORDD.Fields("LINENUM").Value
'go to the next order detail line record
Loop While dsOEORDD.GoNext = True
'If the total cost of the miscellaneous fee is not 0.00 then add a detail line
If totalAmt <> 0# Then
dsOEORDD.Init
dsOEORDD.Fields("LINETYPE").Value = 2
dsOEORDD.Fields("MISCCHARGE").Value = "EHCHGE" ' Item
dsOEORDD.Fields("EXTINVMISC").Value = totalAmt ' Extended Amount
dsOEORDD.Fields("COMPLETE").PutWithoutVerification ("0")
dsOEORDD.Fields("LINENUM").PutWithoutVerification (lineNum)
End If
Set mDBLinkCmpRW = Nothing
Set dsOEORDD = Nothing
End If
End Sub