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

enter comment in PO with macro 1

Status
Not open for further replies.

johnhugh

Technical User
Mar 24, 2010
702
SG
Hi,

I'm trying to write a macro for entering a PO line item comment but can't work out the error I get.
I've taken the code from a macro recording.
The error i get is: Method 'PutWithoutVerification' of object 'IAccpacViewField' failed.

Code:
Private Sub cmdSearch_Click()
Dim temp As Boolean
Dim POPOR1header As AccpacCOMAPI.AccpacView
Dim POPOR1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0620", POPOR1header
Set POPOR1headerFields = POPOR1header.Fields

Dim POPOR1detail1 As AccpacCOMAPI.AccpacView
Dim POPOR1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0630", POPOR1detail1
Set POPOR1detail1Fields = POPOR1detail1.Fields

Dim POPOR1detail2 As AccpacCOMAPI.AccpacView
Dim POPOR1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0610", POPOR1detail2
Set POPOR1detail2Fields = POPOR1detail2.Fields

Dim POPOR1detail3 As AccpacCOMAPI.AccpacView
Dim POPOR1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0632", POPOR1detail3
Set POPOR1detail3Fields = POPOR1detail3.Fields

Dim POPOR1detail4 As AccpacCOMAPI.AccpacView
Dim POPOR1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0619", POPOR1detail4
Set POPOR1detail4Fields = POPOR1detail4.Fields

Dim POPOR1detail5 As AccpacCOMAPI.AccpacView
Dim POPOR1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0623", POPOR1detail5
Set POPOR1detail5Fields = POPOR1detail5.Fields

Dim POPOR1detail6 As AccpacCOMAPI.AccpacView
Dim POPOR1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PO0633", POPOR1detail6
Set POPOR1detail6Fields = POPOR1detail6.Fields

POPOR1header.Compose Array(POPOR1detail2, POPOR1detail1, POPOR1detail3, POPOR1detail4, POPOR1detail5)

POPOR1detail1.Compose Array(POPOR1header, POPOR1detail2, POPOR1detail4, Nothing, Nothing, POPOR1detail6)

POPOR1detail2.Compose Array(POPOR1header, POPOR1detail1)

POPOR1detail3.Compose Array(POPOR1header, POPOR1detail4)

POPOR1detail4.Compose Array(POPOR1header, POPOR1detail2, POPOR1detail1, POPOR1detail3)

POPOR1detail5.Compose Array(POPOR1header)

POPOR1detail6.Compose Array(POPOR1detail1)



POPOR1headerFields("PONUMBER").Value = "PO-0024100"                   ' Purchase Order Number

temp = POPOR1header.Exists
POPOR1header.Read
temp = POPOR1detail3.Exists
POPOR1detail3.Init

POPOR1detail3Fields("PORRREV").PutWithoutVerification ("-999999999999999999")   ' Line Number

POPOR1detail3.Browse "", 1
POPOR1detail3.Fetch
temp = POPOR1detail2.Exists
POPOR1detail2.Init

POPOR1detail2Fields("PORCREV").PutWithoutVerification ("-999999999999999999")   ' Comment Identifier

POPOR1detail2.Browse "", 1
POPOR1detail2.Fetch
POPOR1detail2.Browse "(COMMENTTYP = ""1"")", 1
temp = POPOR1detail2.Exists
POPOR1detail2.RecordClear
temp = POPOR1detail2.Exists
POPOR1detail2.RecordCreate 0
POPOR1detail2.Process

POPOR1detail2Fields("COMMENT").PutWithoutVerification ("test")        ' Comments/Instructions
POPOR1detail2.Insert
End Sub
 
Get rid of all the "temp =" lines, and the PORRREV and PORCREV lines, they're just noise.
 
Thanks tuba. I've done that now.
My code fails at this line
Code:
POPOR1detail2Fields("COMMENT").PutWithoutVerification ("test")        ' Comments/Instructions
[\code]
 
It says "Attempt to change read-only field "Comments/Instructions"

Would this have something to do with having Purchasing Workflow installed?
 
Maybe. I've never done macros with that module installed, only straight PO. PW definitely subclasses PO views.
 
When you recorded the macro did you create a new PO or did you select an existing PO to modify? If you selected an existing PO - was that line complete, by chance?
 
I selected an existing PO but the line wasn't complete.
 
Make sure that you've navigated to the detail line that you want to add the comment to.

Here's a chunk of code that I use:
Code:
    With POOrderDetailComment
        .RecordClear
        .Fields("PORCREV").PutWithoutVerification LastPODetailCommentLine
        .RecordCreate VIEW_RECORD_CREATE_DELAYKEY
        .Fields("COMMENT").PutWithoutVerification aText
        .Insert
        LastPODetailCommentLine = .Fields("PORCREV").Value
    End With
    
    POOrderDetail.Fields("HASCOMMENT").Value = 1
 
Thanks Djangman,
I tried your code but still get the same error message: "Attempt to change read-only field "Comments/Instructions"

Does your macro work on a system that has purchasing workflow installed?
It very odd, I can enter a comment through the normal PO screen but the macro returns an error.

Also, do you not have to define whether it is a comment or an instruction?
Code:
POPOR2detail2Fields("COMMENTTYP").Value = "1" 'comment
 
It will default to a comment type line so I don't specify it.

I'm not running the workflow product.

The only thing I can suggest is running your macro on a set of sample data that doesn't have workflow activated.

You might also have to contact Pacific Technologies for assistance.
 
Hi DjangMan,
I managed to enter a PO comment, however I fail to determine the last comment line and thus my comments are always added on the top, not the bottom.

In my code below I navigate to the PO and line comment.
In the comment section, I start from the bottom line which is an instruction.
To find the last comment I try to go backwards till I find the last 'COMMENTTYP=1'

My 'Loop While POPOR2detail2.GoPrev' does not seem to work though.
It just enters an endless loop never going backwards through the comments.
What am I doing wrong?


Code:
'PO header
POPOR2header.GoBottom
Do
    If POPOR2headerFields("PONUMBER") = "PO-0024087" Then
        Exit Do
    End If
Loop While POPOR2header.GoPrev

'PO line details
POPOR2detail1.GoBottom
Do     'Get Details
    If POPOR2headerFields("PORHSEQ") = POPOR2detail1Fields("PORHSEQ") Then
        Exit Do
    End If
Loop While POPOR2detail1.GoPrev

'comments
'find last comment line
POPOR2detail2.GoBottom
Do
    If POPOR2detail1Fields("PORCSEQ") <> POPOR2detail2Fields("PORCSEQ") Then
        Exit Do
    End If
        
    If POPOR2detail2.Fields("COMMENTTYP") = 1 Then
        LastPODetailCommentLine = POPOR2detail2.Fields("PORCREV")
        POPOR2detail2.RecordClear
        POPOR2detail2.Fields("PORCREV").PutWithoutVerification LastPODetailCommentLine
        POPOR2detail2.RecordCreate VIEW_RECORD_CREATE_DELAYKEY
        POPOR2detail2Fields("COMMENT").PutWithoutVerification ("test5")        ' Comments/Instructions
        POPOR2detail2.Insert
    End If
Loop While POPOR2detail2.GoPrev

POPOR2detail1Fields("HASCOMMENT").Value = 1 'update line item
POPOR2header.Update
 
It looks like you're reading the last number and then replacing it with the last number.
Code:
        LastPODetailCommentLine = POPOR2detail2.Fields("PORCREV")
        POPOR2detail2.RecordClear
        POPOR2detail2.Fields("PORCREV").PutWithoutVerification LastPODetailCommentLine

The view's revision list will insert the record below the one that you supply the key value for. So you want to get the last value for PORCREV for that detail line and use that in your code. Something like:
Code:
    With POOrderDetailComment
        .Browse "", True '<- just make sure this only browses your current detail line's comments
        if .GoBottom then
            LastPODetailCommentLine = .Fields("PORCREV").Value
        else
            LastPODetailCommentLine = -1
        end if
    end with

    With POOrderDetailComment
        .RecordClear
        .Fields("PORCREV").PutWithoutVerification LastPODetailCommentLine
        .RecordCreate VIEW_RECORD_CREATE_DELAYKEY
        .Fields("COMMENT").PutWithoutVerification aText
        .Insert
        LastPODetailCommentLine = .Fields("PORCREV").Value
    End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top