r/MSAccess • u/slightlyfazed 2 • Jun 11 '15
Most Recent Record
I am making a check in-out database to track student in a building. Currently I have tblLog with logID, studentID, dateTime, event -where the event field is storing text, either "CheckIn" or "CheckOut".
What I need to do for my main form is find a way to look at this table and see what the last event was for each student, I've looked at Dlast, with the control source
=DLast("event","tblLog","StudentID = & '[StudentID]'")but I'm mostly making things up at this point.
1
u/06210311 1 Jun 14 '15
Your best solution depends upon how many records you're looking at, and how your table is set up.
Personally, I think that if you're going to use DLOOKUP, it's better to have an Autonumber field and do a DMAX off of that, rather than a DMAX on a time field; in my experience, DMAX gets a bit flaky on Date/Time parameters.
However, as /u/monsieurus and /u/Svx_blue said below, it's probably better to use SQL or recordsets for this kind of thing.
2
u/Svx_blue Jun 11 '15
You were almost there: use a dlookup and a nested dmax on the datetime field to get what you are looking for.
=DLookup("event","tblLog","StudentID = & '[StudentID]' & "and datetime = " & dmax("datetime","tblLog","StudentID = " & '[StudentID]'))
I've found nesting D functions can be effective for things like this on forms but I would avoid using this method any where else in favor of sql statements.