web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Report Writer with VBA calculated fields ignored

(0) ShareShare
ReportReport
Posted on by 1,331

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

I have the same question (0)
  • Verified answer
    DinB Profile Picture
    3,951 on at

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

  • Bill Campbell Profile Picture
    12 on at

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

  • Harold Worby Profile Picture
    1,331 on at

    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.

  • Harold Worby Profile Picture
    1,331 on at

    Got this one,

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans