Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically focusing on a newly created record

Status
Not open for further replies.

agt119

Programmer
Feb 6, 2007
10
AR
Upon closing one form, I'd need a specific item in another form's list to be selected.

Basically:
Form A: main form, lists all records in db
Form B: new record creation form

Upon saving/closing Form B (thus returning to form A), is there a way for the newly created record to be selected in form A?

Thanks in advance!
 
You can use the RecordsetClone of Form A from Form B:

Code:
Set rs = Forms!FormA.RecordsetClone
rs.FindFirst "ID=" & Me.ID
If Not rs.NoMatch Then
    Forms!FormA.Bookmark=rs.Bookmark
End If
 
Thanks very much for getting back to me Remou!

When I tried this, the line
Code:
Forms!FormA.Bookmark=rs.Bookmark"
gave me an error "not a valid marker".

Form B is a subform -- might that be the problem? Do you know what I can do about this?

Thanks a lot!
 
I forgot to say that, as FormB is a subform, what I tried to do was:

Forms!FormA!FormB.Form.Bookmark=rs.Bookmark

instead of

Forms!FormA.Bookmark=rs.Bookmark

Thanks a lot!
 
I missed a requery I should have included, but that does not seem to be the problem. When you say 'subform', do you mean a small form that pops up or a form embedded in FormA? Also, please post the code as amended by you for your application.
 
FormB is embedded in FormA.

Here's the code I added on FormC close. Here FormC is another Form, from where I create the new record, to be shown in Form B.

'on FormC close
Private Sub Form_Close()
Forms![FormA].Recalc
Set rs = Forms![FormA]!FormB.Form.RecordsetClone
rs.FindFirst "order_pk=" & Me.order_pk
If Not rs.NoMatch Then
Forms![FormA]!FormB.Form.Bookmark = Me.Bookmark
End If
End Sub

The bold line is the one which causes the error
 
Maybe a better explanation here, would help.

Form B is embedded in Form A. I open FormC and create a new item. Then upon closing Form C, FormA and its sub form (FormB) should be refreshed, and Form B should show the new item recentrly created from FormC.

Thanks Remou!
 
Forms![FormA]!FormB.Form.Bookmark = [!]rs[/!].Bookmark

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV! that definitely solved the problem. However, it still doesn't go to the recently created record.

Maybe there's another way of doing it? like going to the last updated record? I've seen there's a LastUpdate property in the rs recordset...

Thanks a lot for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top