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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to update line item costs on requisition

Status
Not open for further replies.

johnhugh

Technical User
Mar 24, 2010
702
SG
Hi, I'm using Accpac 6.

I'm trying to use below macro to update line item costs in a PO requisition.
Now this is Purchasing Workflow RQN, but the issue I have should apply for the standard RQN as well.

I basically want to add 7.5% to the line item cost, whci it does in my code, only the new cost does not show up on my RQN.
It seems like the .update does not work.
Do I need to set up the view compositions just to update the item cost?
Appreciate any help on this.

Code:
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim PTMACLOG As AccpacCOMAPI.AccpacView
mDBLinkCmpRW.OpenView "PT0036", PTMACLOG

Dim PTFNCTN As AccpacCOMAPI.AccpacView
mDBLinkCmpRW.OpenView "PT0900", PTFNCTN

Dim PTPRH As AccpacCOMAPI.AccpacView
mDBLinkCmpRW.OpenView "PT0040", PTPRH

Dim PTPRD As AccpacCOMAPI.AccpacView
Dim PTPRDFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PT0041", PTPRD
Set PTPRDFields = PTPRD.Fields

With PTMACLOG
    .RecordClear
    .Order = 1
    .Browse "USERID=""" & strUserID & """ AND LOGSTATUS=1", True
    If .Fetch Then
        strWorkflow = .Fields("WORKFLOW").Value
        strRQNNumber = .Fields("DOCNUMBER").Value
        intWorkflowType = .Fields("WRKFLWTYPE").Value
        dblSequence = .Fields("SEQUENCE").Value
        dblMacroID = .Fields("MACLOGID").Value       
            
        'find RQN Number
        With PTPRH
            .RecordClear
            .Order = 0 '
            .Browse "RQNHSEQ=" & dblSequence & "", True
            If .Fetch Then
                'get details of RQN number               
                With PTPRD
                    .Order = 0
                    .Browse "RQNHSEQ=" & dblSequence & "", True
                    If .Fetch Then
                        .GoTop
                        Do
                            CurUnitCost = Round(.Fields("UNITCOST").Value * 1.075, 2)
                            PTPRDFields("UNITCOST").Value = CurUnitCost
                            .Update                                                
                        Loop While .GoNext                      
                    End If
                End With
      
            PTPRH.Update
            End If
        End With
 
OK. Tried it as below now and it seems to work when using compositions.
Could someone explain what the compositions are actually doing?

Code:
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim PTPRH As AccpacCOMAPI.AccpacView
mDBLinkCmpRW.OpenView "PT0040", PTPRH

Dim PTPRHO As AccpacCOMAPI.AccpacView
mDBLinkCmpRW.OpenView "PT0816", PTPRHO

Dim PTPRD As AccpacCOMAPI.AccpacView
Dim PTPRDFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PT0041", PTPRD
Set PTPRDFields = PTPRD.Fields

PTPRH.Compose Array(PTPRD, PTPRHO, Nothing)
PTPRD.Compose Array(PTPRH, Nothing, Nothing)

With PTMACLOG
    .RecordClear
    .Order = 1
    .Browse "USERID=""" & strUserID & """ AND LOGSTATUS=1", True
    If .Fetch Then
        strWorkflow = .Fields("WORKFLOW").Value
        strRQNNumber = .Fields("DOCNUMBER").Value
        intWorkflowType = .Fields("WRKFLWTYPE").Value
        dblSequence = .Fields("SEQUENCE").Value
        dblMacroID = .Fields("MACLOGID").Value
                           
        'find RQN Number
        With PTPRH
            .RecordClear
            .Order = 0 '
            .Browse "RQNHSEQ=" & dblSequence & "", True
            If .Fetch Then
                'get details of RQN number
                With PTPRD
                    .Order = 0
                    .Browse "RQNHSEQ=" & dblSequence & "", True
                    If .Fetch Then
                        .GoTop
                        Do
                            CurUnitCost = Round(.Fields("UNITCOST").Value * 1.075, 2)
                            PTPRDFields("UNITCOST").Value = CurUnitCost
                            PTPRD.Update                                                
                        Loop While .GoNext
                    End If
                End With
      
            PTPRH.Update
            PTPRH.Process
            End If
        End With
 
They're composing views... i.e. linking tables on keys in regular programming languages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top