Make your target record the subform's current record. Then use RunCommand
to "select" it ... which will also highlight the record.
DoCmd.RunCommand acCmdSelectRecord
Seems like your question is morphing into "how do I make the last added record the current record".
If the last added record is still the current record, then you're there already, so no problem.
If the user navigated to a different record after adding the last one, there are at least 2 ways to get back to it.
DoCmd.GoToRecord
- Use a find method on the recordset clone.
Choose the approach which best fits your situation. If the bound value of your combo box is the numeric primary key for the row last added, you can try that second suggestion like this by replacing pkey_field
, YourComboNameHere
, and SubformControl
with the actual names you're using.
Private Sub FindLastRecordAdded()
Dim rst As DAO.Recordset
Dim strCriteria As String
strCriteria = "[pkey_field] =" & Me.YourComboNameHere
Set rst = Me.SubformControl.Form.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "Oops. This shouldn't happen.", vbInformation
Else
Me.SubformControl.Form.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End Sub
Best Answer
Please first make sure your recordsource is updateable by opening the table or query in which your subform recordsource is based, and ensure that you can edit and add new records. If not, then it's possible that your SQL Server linked table is missing a unique indentifier. To create one, simply delete the linked table, and relink it. Upon relinking, MS Access should prompt you to specify a unique index (may take more than one field to make it truly unique). Then try again.