Tuesday, February 05, 2013 8:26 PM
I´m new to the forum. I´m currently using MS Access 2010.
I´m trying to figure out how to add an event to a form, that displays the "last modified record" when opening the form (instead of the first, last of new record). I currently have a field called "LastMod" in my table, that has a macro that sets the value for Now() (applied before updating the record)
Any guidance is sincerely appreciated.
Tuesday, February 05, 2013 8:35 PM
Because you have that field you're half way there. Depending on how you want to trigger this move, you could use a command button or just use the form's Load event.
Private Sub Command2_Click() Me.Recordset.FindFirst "LastMod=#" & DMax("LastMod", "Customers") & "#" End Sub
DMax will find the maximum (Latest) date in the LastMod field. FindFirst will use that value to move to that record.
Tuesday, February 05, 2013 8:41 PM
Add your 'LastMod' to your ORDER BY using a subquery --
IIf((SELECT Max([XX].[LastMod]) FROM YourTable AS [XX])=YourTable.LastMod,0,1) AS LastModRec
Tuesday, February 05, 2013 8:43 PM
Let's say the table is named tblData.
Create an On Load event procedure for the form:
Private Sub Form_Load() With Me.RecordsetClone .FindFirst "LastMod = " & CDbl(DMax("LastMod", "tblData")) Me.Bookmark = .Bookmark End With End Sub
Regards, Hans Vogelaar
- Marked As Answer by Csupo Wednesday, February 06, 2013 12:34 AM
Wednesday, February 06, 2013 12:41 AM
I thank you very much. This was exactly what I needed.
You´re all great and very helpful.