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!

TextBox to display last record on subform 1

Status
Not open for further replies.

CountyArchitect

Technical User
Aug 24, 2007
4
US
Greeting:

I have a main form of members with a filtered subform with individual payments made by the member (filtered) from the main form.

There is a textbox that preforms a DSum of all payments made by that particular member on the main form. What I would also like to see is the last payment amount made by this particular member on the main form.

I tried the following--but it returns a random record from the filtered set...not the last record.

=IIf(IsNull([MemberID]),0,DLast("[PaymentAmount]","Payments","[MemberID]=" & [MemberID]))

What am I missing?

Thanks much for the help.


 
DLast() and Last are basically random. There is no order to records. They are like marbles in a bag with no first or last. You would need to change the where condition to include the maximum date and use DLookup(). I would probably create a query qgrpLastPayments that returns the most recent payment information for each MemberID

Code:
SELECT *
FROM Payments
WHERE PaymentDate = (SELECT Max(PaymentDate) FROM Payments P2 WHERE P2.MemberID = Payments.MemberID);

Then your DLookup would be
Code:
DLookup("PaymentAmount","qgrpLastPayments","[MemberID]=" & [MemberID])



Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top