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

How to Keep the Focus on a Current Record 1

Status
Not open for further replies.

webvine

Technical User
Oct 21, 2002
20
Hello,
I have a subform that I am utilizing and on that subform are 5 command buttons each when clicked opens up a small form that I input information that is unique to that subform record I am on. My problem is as follows, lets say I have 10 records in that subform, if I am on record #6 and I click one of the 5 command buttons to enter information when I close the window the focus does not stay on record #6 it reverts back to record #1. Then I have to click through to record #7, go through the process again and when I close the window of 1 of the 5 command buttons it does not stay on record #7 it reverts back to record #1 and so it goes. How do I keep the focus on the current record? Thanks in advance for any help.
 
Hi!

From your description I figure it might be a requery challenge. I think either you have a line stating "me.requery" or the operation you perform executes a requery on the form, which requeries the recordset, and thereby going to the forms first record.

If you're using me.requery, you might consider trying:

[tt]me.refresh[/tt]

HTH Roy-Vidar
 
Ok...I see on the subform code it does say Me.Requery I change it to Me.Refresh but it doesn't seem to solve the problem, any other isuggestions?
 
OK you might try the following:

In (each of) your command buttons, add some code:

[tt] dim lId as long
dim rs as dao.recordset ' If your using access 2000+
' also go to Tools | References in modules and check
' the Microsoft DAO 3.N Library (N-some numeric)
' remove the "dao." part if you're using 97

set rs=me.recordsetclone
lId=me!txtID ' assuming a numeric ID field on your form

docmd.openform "yourform",,,,,acdialog ' Your current openform

rs.findfirst "ID = " & lID
me.bookmark=rs.bookmark
set rs=nothing[/tt]

This is assuming numeric id field in the table, just substitute ID with your field name and txtID with your control name.

If your ID field is text, substitute
[tt]dim lID as long[/tt] with
[tt]dim sID as string[/tt]

[tt]lId=me!txtID[/tt] with
[tt]sId=me!txtID[/tt]

[tt]rs.findfirst "ID = " & lID[/tt] with
[tt]rs.findfirst "ID = '" & sID & "'"[/tt]

HTH Roy-Vidar
 
Thank You so much, I took your code and after a few hours of figuring out, trying out and testing it out, your solution was a success. I understood some of the code but not all but I went ahead and bit by bit tried to make it work. I think the key had something to do with the bookmark part. Again, thank you so much.
 
Hi!

Nice to hear that you made it work!

Just post your questions, and we'll try to answer - 'nother good hint, is placing the cursor in a function/method name and hit F1.

And yes, it's sometimes easyer to assist, when there's some more information around (form/table/query/field/control-names...)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top