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!

PW PO SEQUENCE KEY 1

Status
Not open for further replies.

Boris10

IS-IT--Management
Jan 26, 2012
97
KE
Hi Everyone,

I have recorded a macro that submits a PO for approval in PW. Now i am trying to insert the result of my code into the macro so that a PO is created from another macro. The code works and allows me to enter a PO and it even appears in the PW Purchase Order Entry Screen. However, i am failing to automatically submit the PO.

I think the Problem lies with the Sequence key. If i set the sequence key to an already existing key the PO status is set to "Entered". If i set the Sequence key to max(key)+128 (i.e create my own) i get an error:

"Could not get workflow information. Unable to process document"

Code:
With rec
        .CursorLocation = adUseClient
        .CursorType = adOpenDynamic
        .LockType = adLockBatchOptimistic
        Set .ActiveConnection = cn
        .source = "select max(PORHSEQ) MAXX FROM OLDDAT.DBO.PTPORH"
        .Open
End With
Nxt = rec.Fields(0).value + 128
POPOR4header.Order = 1
POPOR4header.Order = 0

POPOR4headerFields("PORHSEQ").PutWithoutVerification ("0")            ' Purchase Order Sequence Key

POPOR4header.Init
POPOR4header.Order = 1
temp = POPOR4detail1.Exists
POPOR4detail1.RecordClear
POPOR4detail3.Init
POPOR4detail2.Init
POPOR4headerFields("VDCODE").value = Me.txtVendorNumber.Text                        ' Vendor

POPOR4headerFields("PROCESSCMD").PutWithoutVerification ("1")                       ' Command

POPOR4header.Process

POPOR4headerFields("COSTCTR").value = Me.EmployeeGrid.TextMatrix(1, 1)               ' Cost Center
POPOR4headerFields("DESCRIPTIO").value = Me.txtDescription.Text                      ' Description
POPOR4headerFields("REFERENCE").value = Me.txtReference.Text                         ' Reference

temp = POPOR4detail1.Exists
POPOR4detail1.RecordClear
temp = POPOR4detail1.Exists
POPOR4detail1.RecordCreate 0
With EmployeeGrid
    For a = 1 To .Rows - 1
        POPOR4detail1Fields("ITEMNO").value = .TextMatrix(a, 2)                     ' Item Number
        POPOR4detail1Fields("PROCESSCMD").PutWithoutVerification ("1")              ' Command
        POPOR4detail1.Process
        POPOR4detail1Fields("LOCATION").value = "MINE"                              ' Location
        POPOR4detail1Fields("OQORDERED").value = .TextMatrix(a, 4)                  ' Quantity Ordered
        POPOR4detail1Fields("UNITCOST").value = .TextMatrix(a, 5)                   ' Unit Cost
        POPOR4detail1Fields("DISCPCT").value = .TextMatrix(a, 6)                    ' Discount Percentage
        POPOR4detail1.Insert
        POPOR4detail1Fields("PORLREV").PutWithoutVerification ("-" & a & "")        ' Line Number
        POPOR4detail1.Read
        temp = POPOR4detail1.Exists
        POPOR4detail1.RecordCreate 0
    Next a
End With
POPOR4detail4Fields("FUNCTION").PutWithoutVerification ("8")          ' Function
POPOR4detail4.Process
temp = POPOR4header.Exists
POPOR4header.Insert
PTFNCTN3Fields("FUNCTION").PutWithoutVerification ("20")              ' Function

PTFNCTN3Fields("WORKFLOW").PutWithoutVerification ("PO")              ' Workflow
PTFNCTN3Fields("TYPE").PutWithoutVerification ("20")                  ' Workflow Type
PTFNCTN3Fields("KEY").PutWithoutVerification ("" & Nxt & "")             ' Sequence Key

PTFNCTN3.Process
POPOR4header.Init
POPOR4header.Order = 0
How can i change my code to automatically submit a PO in PW from another macro
 
You need to set Nxt = POPOR4headerFields("PORHSEQ").Value after POPOR4header.Insert
if I read it correctly. I have no clue what PF / PW / workflow is, but assume it is Pacific Tech purchasing workflow?
 
I cleaning up your code a bit, you can delete all the TEMP= crap as well as the .Init and .Clear lines.
I typically rename the views from POPOR4 to just PO and drop all the POPOR4headerFields and just use POPOR4header.Fields instead - that's just my preference.
I moved POdetail1.RecordCreate 0 inside the For...Next and removed the lines after the .Insert.

Code:
POheader.Order = 0
POheader.Fields("PORHSEQ").PutWithoutVerification ("0")            ' Purchase Order Sequence Key
POheader.Init
POheader.Order = 1

POheader.Fields("VDCODE").Value = Me.txtVendorNumber.Text                        ' Vendor
POheader.Fields("PROCESSCMD").PutWithoutVerification ("1")                       ' Command
POheader.Process

POheader.Fields("COSTCTR").Value = Me.EmployeeGrid.TextMatrix(1, 1)               ' Cost Center
POheader.Fields("DESCRIPTIO").Value = Me.txtDescription.Text                      ' Description
POheader.Fields("REFERENCE").Value = Me.txtReference.Text                         ' Reference

With EmployeeGrid
    For a = 1 To .Rows - 1
        POdetail1.RecordCreate 0
        POdetail1.Fields("ITEMNO").Value = .TextMatrix(a, 2)                     ' Item Number
        POdetail1.Fields("PROCESSCMD").PutWithoutVerification ("1")              ' Command
        POdetail1.Process
        POdetail1.Fields("LOCATION").Value = "MINE"                              ' Location
        POdetail1.Fields("OQORDERED").Value = .TextMatrix(a, 4)                  ' Quantity Ordered
        POdetail1.Fields("UNITCOST").Value = .TextMatrix(a, 5)                   ' Unit Cost
        POdetail1.Fields("DISCPCT").Value = .TextMatrix(a, 6)                    ' Discount Percentage
        POdetail1.Insert
    Next a
End With
POdetail4.Fields("FUNCTION").PutWithoutVerification ("8")          ' Function
POdetail4.Process
POheader.Insert

Nxt = POheader.Fields("PORHSEQ").Value

PTFNCTN3.Fields("FUNCTION").PutWithoutVerification ("20")              ' Function
PTFNCTN3.Fields("WORKFLOW").PutWithoutVerification ("PO")              ' Workflow
PTFNCTN3.Fields("TYPE").PutWithoutVerification ("20")                  ' Workflow Type
PTFNCTN3.Fields("KEY").PutWithoutVerification ("" & Nxt & "")             ' Sequence Key
PTFNCTN3.Process
 
You could also do:

Code:
PTFNCTN3.Fields("KEY").PutWithoutVerification POheader.Fields("PORHSEQ").Value
 
Hi Ettienne,

I just tried the code
Code:
Nxt = POheader.Fields("PORHSEQ").Value
It works Perfectly. Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top