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!

Calculation in Report

Status
Not open for further replies.

Thistlestop

Technical User
Oct 9, 2006
3
US
On a report, one control is 'xxx'. It's any digit from 1 thru 6. I need to calculate the DIFFERENCE between the CURRENT value of xxx (current line on the report) and the PRIOR value (last line on the report). For example, if the current value is 5 and the prior value is 3, I want to show a 2 adjacent to the 5 (since the increase from 3 to 5 is 2).

I tried the following code but I can't get it to work. (I used MsgBox to test).

1. Is the line: txtDifference = xxx- ILast correct?
2. MsgBox does NOT show the correct values in xxx
3. Once I get this to work, HOW DO I DISPLAY THE txtDifference VALUE ON THE REPORT ITSELF?


Thanks, Mike




Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Dim ILast As Long
Dim txtDifference As Long
Dim xxx As Long

txtDifference = xxx- ILast
' I want to display txtDifference on the report now
ILast = xxx
' MsgBox xxx
' Set ILast to the current xxx
' When I get the NEXT xxx I then calculate the NEXT difference

End Sub
 
I would calculate the "prior" value in the report's record source query. This would use either a subquery or dlookup() or similar.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top