You might be able to Requery the subform, and then go to the last record.
But if the table does not have an AutoNumber, or if the AutoNumber is not
sequential, or if other users are adding records, this might not take you to
to desired one.
Would you consider an AddNew on the RecordsetClone of the subform instead of
running the update query? That avoids the Requery, and you know for certain
that you are ending up with the correct record.
This kind of thing (assuming the code goes in the main form's module):
Dim rs As DAO.Recordset
With Me.Child135.Form
Set rs = .RecordsetClone
rs.AddNew
rs!conf = Confirm
rs!csrID = use
rs!csdate = Date()
rs!comments = "cxl"
rs.Update
.Bookmark = rs.LastModified
End With
Set rs = Nothing
The alternative would be to Execute the query statement instead of RunSQL,
and ask Access for the new identity value, requery the subform, and then
FindFirst in its RecordsetClone. That's a long way round for a shortcut, and
works in JET 4 only (Access 2000 and later.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<co*****@yahoo.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Below is my code. What I want do is ,after running the insert
statement into tblarchive, I want to go to the subform and set focus to
the record that I just added in
Confirm = "'" + CONF + "'"
usr = "'" + CurrentUser() + "'"
strSQL = "INSERT INTO tblarchive ( conf, csrID, csdate, comments )
SELECT " & Confirm & " AS Expr1, " & usr & " AS Expr2, Date() AS
Expr3, 'cxl' AS Expr4;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL (running the insert sql statement)
DoCmd.SetWarnings True
DoCmd.Close acForm, "cancel", acSaveYes
Forms![MAIN-members]![Child135].SetFocus (set focus to the
subform)
Forms![MAIN-members]![Child135]!comments.SetFocus
DoCmd.GoToRecord (need help here go to the record that just ran
above)