Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Report Writer with VBA calculated fields ignored

Posted on by 1,325

In GP2010 I'm modifying the 'Historical Stock Status Summary Report by Site' and adding some new fields. The new fields are defined as calculated String fields and are set in the  Report_BeforeAF() subroutine. One field is calculated from data on the report already and the others are filled in from an SQL query.

Every thing works as expected except that the calculated fields are all blank for the first item one each page after page 1. Page one prints correctly then one each subsequent page the first line displays none of the calculated fields, the rest of the page displays correctly.

I've printed the report to a text file and get the same results.

Even went so far as to open a text file and print the data to that file as the report runs. That file ends up with the correct data for all records proving the code is being called and supplying the correct data. RW just ignores the calculated fields on the first line of every page.

WTF?????

The Code:

Private Sub Report_BeforeAF(ByVal Level As Integer, SuppressBand As Boolean)

' For testing this is were I opened a text file for append and wrote the Level and the Item number to it
    If Level = 2 Then
        Dim ItemNum As String
        Dim Rs As New ADODB.Recordset
        Dim SQL As String
        Dim Qty As Double, Cost As Double
        Me.kkLastRecCostLASTF2 = "-"
        Me.kkLastRecDateLASTF2 = "-"
        Me.kkOrigCostLASTF2 = "-"
        Me.kkUofMLASTF2 = "-"
        Me.kkAveCOstLASTF2 = "-"
       
        ItemNum = Trim(Me.ItemNumberLASTF2.Value)
       
        Cost = CDbl(Me.ExtendedPriceSUMF2)
        Qty = CDbl(Me.TRXQTYSUMF2)
       
        If Qty <> 0 Then
            Me.kkAveCOstLASTF2 = Format(Cost / Qty, "###,##0.000")
        Else
            Me.kkAveCOstLASTF2 = "-"
        End If
        SQL = "SELECT top 1 last_originating_cost, lrcptcst, lsrcptdt"
        SQL = SQL & " FROM IV00103"
        SQL = SQL & " WHERE ITEMNMBR ='" & ItemNum & "' ORDER BY lsrcptdt Desc"
        Rs.Open SQL, kkCommon.GetCon
        If Not Rs.EOF Then
            Me.kkLastRecDateLASTF2 = Rs.Fields("lsrcptdt").Value
            Me.kkLastRecCostLASTF2 = Format(Rs.Fields("lrcptcst").Value, "###,##0.000")
            Me.kkOrigCostLASTF2 = Format(Rs.Fields("last_originating_cost").Value, "###,##0.000")
        End If
        Rs.Close
        Rs.Open "select baseuofm from iv40201 where uomschdl=(select uomschdl from iv00101 where itemnmbr='" & ItemNum & "')"
        If Not Rs.EOF Then
            Me.kkUofMLASTF2 = Rs.Fields(0).Value
        End If
        Rs.Close
        Set Rs = Nothing
   End If

' During testing I wrote the calculated fields here and closed the file
End Sub

*This post is locked for comments

  • Harold Worby Profile Picture
    Harold Worby 1,325 on at
    RE: Report Writer with VBA calculated fields ignored

    Got this one,

    Export the Package file , edit the package file to remove references, import the package file.

  • Harold Worby Profile Picture
    Harold Worby 1,325 on at
    RE: Report Writer with VBA calculated fields ignored

    That solved the issue, but caused the VBA names to no longer be valid.

    I had to re-add them to VBA. They all dropped the [LASTF2] part.

    Is there a way to remove fields from VBA? the ???LASTF2 references are still there.

  • Bill Campbell Profile Picture
    Bill Campbell 22,647 on at
    RE: Report Writer with VBA calculated fields ignored

    Max, that was literally what I was typing when your answer poped on my screen.

  • Verified answer
    DinB Profile Picture
    DinB 3,812 on at
    RE: Report Writer with VBA calculated fields ignored

    Try following in the test environment:
    Open "Report Field Options" for the Calculated fields and Change "Display Type" from "Last Occurrence" to "Data".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans