Remember Last Record

BrianB75

Registered User.
Local time
Today, 07:34
Joined
Aug 27, 2004
Messages
43
I currently have a form that displays a number of records and allows the user to double-click on a record to open up a detail screen. The problem I am running into is that as soon as the user closes the detail form and reopens the main form (with all of the records) it goes back to the top of the list. Is there a way in Access to remember what record was selected and then make that record the focus/highlighted record when the user returns to that form?

I tried finding a way to use the SetFocus but I could not determine how to make it work with a specific record.

Thanks.
 
it shouldn't do that, unless you are running a me.requery after you open the popup form.

the requery extracts the information again, and therefore starts at the top
 
I think a requery is automatic on closing a sub-form when data has been added. (Not sure about what happens if it was read-only.)

The way to do this is to understand event flow and bookmarks. Look up event flow to double-check me on this because I'm shooting from the hip.

Your description (to my viewpoint) says you have a parent/child form setup.

So... on the sub-form control's click event, before you open the detail form, set a bookmark on your current record on the parent form.

On the sub-form control's GotFocus event (which fires when the detail form closes) make your form's recordset return to the bookmark.

I'll say that your best bet here is to carefully look at event flow to get the order of events fixed in your head. What you want is to set a bookmark BEFORE you open the detail subform and seek the bookmark AFTER you close the detail subform. If you pick different events but get the order right, then I haven't steered you too badly wrong.

I believe that when you open the detail, since it is a sub-form it gains focus. When the detail closes, the parent's sub-form control regains focus because you are changing focus between parent and child. So take some advantage of that if you can.
 
The problem I am running into is that as soon as the user closes the detail form ...... and reopens the main form.

There lies the problem. In the double click event you must be closing the main form. Simply remove this line. The original form will update by itself when you close the popup form.
 
There lies the problem. In the double click event you must be closing the main form. Simply remove this line. The original form will update by itself when you close the popup form.

I thought about and tried that but I am using a SetValue to tell the detail form which record to display and the SetValue closes the main form when it runs. Is there a better way to send a value to a query/form without using SetValue?
 
I looked at the Bookmark controls but it would appear to cause the same problem since the bookmark would be lost when the main form is closed by the SetValue.

Any ideas on how to pass a selected value from one form to another? So I create a new topic for this?

Thanks again. :)
 
I found a workaround. I didn't actually need the SetValue command as the detail form's query is using criteria based on the active record on the main form. By removing the SetValue and just minimizing the main form when the Detail form is loaded the record position is saved. Then, when the user closes the detail form the macro maximizes the main form.

Thanks again. Sometimes it really helps to bounce things off other people. :D
 

Users who are viewing this thread

Back
Top Bottom