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

Storing numbers until next record

Status
Not open for further replies.

DianeA

Programmer
Nov 15, 2007
56
0
0
CA
I've got a report which is generated from a query. For each record in the query I calculate Qty * dollars. But there are records which will have 0 in the qty so I need to use the last known qty for the next records until the qty is no longer 0. The total dollars are summarized.

Not sure how to store the last known qty.
 
You can add a new table lastQuantity. Everytime an item is used, either update the quantity or add the item into it. Its difficult to know what needs to be done without any additional information though.
 
An alternative would be to use a function.

Code:
Option Compare Database
Option Explicit

Dim varLNo

Function LastNo()
If IsNull(varLNo) Then
    varLNo = Me.[Qty]
End If

If Me.Qty= 0 Then
    LastNo = varLNo
Else
    LastNo = Me.Qty
    varLNo = Me.Qty
End If
End Function

This can be used in a Textbox:

=LastNo()
 
The function is working wonderfully.. thanks. Now... can I use that textbox in a calculation? I've named the textbox "Last" and used it to multiple with another field but I get #Name?

 
sorry... got it working..

thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top