bcooler
Programmer
- Jun 13, 2009
- 132
Hello-
I have a need to look up the record number (auto-numbered primary key) of the earliest (and latest) record in my recordset. I've been stuck trying to use DMIN and DMAX, but I find it does not accomplish what I want.
As best I can tell, the field that it uses to search on is the only field returned. I want to search on the date field and THEN return the record number.
To accomplish this I had to use this really nasty code here, which works, but I've got to know there's a cleaner way. Any ideas?
Thanks!
Brian
I have a need to look up the record number (auto-numbered primary key) of the earliest (and latest) record in my recordset. I've been stuck trying to use DMIN and DMAX, but I find it does not accomplish what I want.
As best I can tell, the field that it uses to search on is the only field returned. I want to search on the date field and THEN return the record number.
To accomplish this I had to use this really nasty code here, which works, but I've got to know there's a cleaner way. Any ideas?
Code:
EarliestEntry = DLookup("[Date_ID]", "tblTravelInfo", "[Expense_ID] = " & Forms!frmExpense.Form.txtExpense_ID & " AND ExpenseDate = #" & DMin("ExpenseDate", "tblTravelInfo", "[Expense_ID] = " & Forms!frmExpense.Form.txtExpense_ID) & "#")
Thanks!
Brian