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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform to Display Last Record Used

Status
Not open for further replies.

PaulaJ

Programmer
Jun 20, 2000
130
0
0
US
How do I make my Subforms that have many records stay on the same record that I used last? I have to use the Requery to display any changes made in the additional screen back to the Subform. Is there a way to identify where I want the subform positioned even using the Requery?

Example: If I have 50 records loaded to my subform, when I select #35 an additional screen displays allowing update of this record. When I Close the additional screen, the Subform is redisplayed starting with the #1 Record containing any changes made in this additional screen. I would like it to stay on the record/position in subform that was just updated (#35).
 
Pick up the Bookmark and reset the recordset to the Bookmark.


rolliee
 
Bookmarks can be invalidated by requery, rather pick up the primary key for the subform, and use .findfirst. Something like this with a numeric PK.

[tt]dim lTmp as long
dim rs as dao.recordset
lTmp = Me!txtPkBox.Value
Me.Requery
set rs=me.recordsetclone
rs.findfirst "PKFieldName = " & lTmp
if not rs.nomatch then me.bookmark=rs.bookmark
set rs=nothing[/tt]

- typed not tested

Roy-Vidar
 
Thanks for the answer. I finally have time to try it out. However, I can't get it to compile. I get a "user defined type not found" on the Dim rs as DAO.Recordset. If I take out the DAO, the NoMatch shows as "Method or Data Member Not Found". The Project Name is an index (CHAR 7) but not a PK.
Here is my code:
Dim lTmp As Long
Dim rs As DAO.Recordset
lTmp = Me![ProjectName].Value
Me.Requery
Set rs = Me.RecordsetClone
rs.Find "ProjectName = " & lTmp
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
Set rs = Nothing
 
Hi again!

In any module, in the Tools | References, set a reference to Microsoft 3.# Object Library.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top