Solved Focus on continuous form (1 Viewer)

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
Hello,

I have a continuous form on which the user can navigate through record. When found, the user can click on a record to view or edit it (nothing new here).

The continuous form (let’s call it LogHeader) is a subform of a form (LogList) and on the form there is a header than contains filters.

The user can use the filter, to filter record element for easier and faster analysis. When using filters, and upon clicking “save” and close, I would like the user to be able to see its updated record on the continuous form.

I tried the Forms!LogList.Refresh and Forms!LogList.Requery but neither would place the “current record” first (using the Forms! Because the code is running on the editing form).

I saw many times the possibility to use the Me.Bookmark or the rs.findfirst but in the last instance I am confused with what shall be the rs in my situation. (like here for example: Jump to a specific record in a continuous form | Access World Forums (access-programmers.co.uk))

As I mentioned the code is running on the editing form and neither on LogHeader nor LogList (maybe that’s the issue). Or maybe the use of the filter shall be included in the mix.

Thanks.
Bob
 

Minty

AWF VIP
Local time
Today, 07:44
Joined
Jul 26, 2013
Messages
10,371
As long as the form you are trying to match the record number with has the same PK field, you can pass that in to the recordset (clone I assume) find method, and get to the same record you where on.

Your description is a little confusing (for me at least), do you have a picture of the forms involved and how they interact?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
I have to say I am equally confused on what form is where.
I interpreted to mean

Main Form LogList
Main Form Header has filter controls (Or maybe this is in the subform header unclear)
Continuous subform LogHeader

I would have thought you simply filter the subform until you find what you want and then click on the thing you want to view or edit, popping up the edit/view detail form.

I interpret the following to mean you pop open the detail form and once closing the detail form you want to return to the selected record. If that is not correct, I do not know what that means.
"When using filters, and upon clicking “save” and close, I would like the user to be able to see its updated record on the continuous form."

How to pop open a detail form and then return to the record showing updates

Code:
dim ID as long ' adjust as necessary
set ID = me.primarykeyfield
docmd.openform "frmPopUp", , , "primarykeyfield = " & ID, acdialog
'need acdialog to stop code execution
'code resumes here once pop up closes
me.requery
me.recordset.findfirst "primarykeyfield = " & ID

That will move the record selector to the correct field, but may or may not move it to the top of the continuous form.
 

LarryE

Active member
Local time
Yesterday, 23:44
Joined
Aug 18, 2021
Messages
591
The user can use the filter, to filter record element for easier and faster analysis. When using filters, and upon clicking “save” and close, I would like the user to be able to see its updated record on the continuous form.

I tried the Forms!LogList.Refresh and Forms!LogList.Requery but neither would place the “current record” first (using the Forms! Because the code is running on the editing form).
When you refresh a form (any form), the focus shifts to the first record automatically. So if you want the user to refresh just the field they changed, you can recalc just that field. So if you have a field in LogList named MyField, you can Recalc the field by:

Forms!LogHeader!LogList!MyField.Recalc or Me.MyField.Recalc

Use the MyField After Update Event

Edit:
Oops, if LogHeader is the suform that should be:
Forms!LogList!LogHeader!MyField.Recalc or Me.MyField.Recalc
 
Last edited:

ebs17

Well-known member
Local time
Today, 08:44
Joined
Feb 7, 2020
Messages
1,946
When using filters, and upon clicking “save” and close, I would like the user to be able to see its updated record on the continuous form.
Do (literally) what you say.
Code:
With Me.SubFormControlName.Form
   .Filter = sYourDeterminedFilter
   .FiterOn = True
End With
If you filter, you will only see your desired records, or an empty recordset.
There is no need for action on Refresh, Requery, Bookmark.
FindFirst is not a filter, but a search, and is usually slower than filtering.
When filtering, you see all possible results at once.

If you address the subform as shown, you don't have to explicitly set a focus in any way.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
As stated this is confusing. Four responses and four different interpretations.
 

ebs17

Well-known member
Local time
Today, 08:44
Joined
Feb 7, 2020
Messages
1,946
Filtering out a subform from the main form - I don't have to interpret it, I just have to write it down.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
Filtering out a subform from the main form - I don't have to interpret it, I just have to write it down.
Well look at you there Einstein. Must be a mind reader too.
 

LarryE

Active member
Local time
Yesterday, 23:44
Joined
Aug 18, 2021
Messages
591
Well look at you there Einstein. Must be a mind reader too.
Nobody has ever accused me of being at a high level on the intelligence spectrum either, but I Identify as pure genius, so there you go! 😁 :rolleyes:
 

ebs17

Well-known member
Local time
Today, 08:44
Joined
Feb 7, 2020
Messages
1,946
The continuous form (let’s call it LogHeader) is a subform of a form (LogList) and on the form there is a header than contains filters.
That's how it's written, not just thought.
I find something like this well and sufficiently described so that I can immediately find an understanding. This task seems clear to me; I let the failed attempts pass by practically unread.

I repeat: do what you want, exactly like that. There is obviously nothing wrong with the project or, if applicable, with the structures.

But thank you for sharing your opinion.
 

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
I have to say I am equally confused on what form is where.
I interpreted to mean

Main Form LogList
Main Form Header has filter controls (Or maybe this is in the subform header unclear)
Continuous subform LogHeader

I would have thought you simply filter the subform until you find what you want and then click on the thing you want to view or edit, popping up the edit/view detail form.

I interpret the following to mean you pop open the detail form and once closing the detail form you want to return to the selected record. If that is not correct, I do not know what that means.
"When using filters, and upon clicking “save” and close, I would like the user to be able to see its updated record on the continuous form."

How to pop open a detail form and then return to the record showing updates

Code:
dim ID as long ' adjust as necessary
set ID = me.primarykeyfield
docmd.openform "frmPopUp", , , "primarykeyfield = " & ID, acdialog
'need acdialog to stop code execution
'code resumes here once pop up closes
me.requery
me.recordset.findfirst "primarykeyfield = " & ID

That will move the record selector to the correct field, but may or may not move it to the top of the continuous form.
Hi,
Thanks for trying to help. I’ll rephrase:
Main form: loglist. Has filters. It is used as a sort of header for the continuous form.
subform: logheader. Is a continuous form.
as you said,
Do (literally) what you say.
Code:
With Me.SubFormControlName.Form
   .Filter = sYourDeterminedFilter
   .FiterOn = True
End With
If you filter, you will only see your desired records, or an empty recordset.
There is no need for action on Refresh, Requery, Bookmark.
FindFirst is not a filter, but a search, and is usually slower than filtering.
When filtering, you see all possible results at once.

If you address the subform as shown, you don't have to explicitly set a focus in any way.
Thanks for your answer.
My problem is 1/ the need to show the updated record on the continuous form and 2/ to focus the continuous form on the current record after the requery/refresh.
The user could be updating or editing only one instance of the filtered list and not only one record. Thus the need to focus on the currently updated record.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
Sorry. I do not have the uncanny insights and clarity of thought of @Ebs17. I am way denser so help me out.
1. Is your filter working to filter the continuous form or do you need help with that? If you need help what is your current code or query used to filter the subform
2. If the filter is working does the filter return more than one record? If it returns one record than I do not think the question about "focus" is relevant.
3. If the filter returns more than one record then what do you mean by the "currently updated record"? Are you working on a record in the continuous form then apply a filter and want to return to the same record?
4. Where are you requerying? Do you mean after you apply the filter or do you requery somewhere in code?

Again @Ebs17 probably can figure this out intuitively, but for me and maybe the rest of us an image of how this is set up, your code, or better yet an uploaded DB would really clarify. My guess this is an easy fix, but your terminology I believe is confusing to what you really mean or as I said I am just too dense to understand the ask.
 

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
I interpret the following to mean you pop open the detail form and once closing the detail form you want to return to the selected record. If that is not correct, I do not know what that means.
That's correct. But as stated in the other answer, the user can filter on Field1 and have multiple records and edit one particular record. Thus the question. It will also avoid the need to scroll back again to the current record to continue their editing.
Main Form LogList
Main Form Header has filter controls (Or maybe this is in the subform header unclear)
Continuous subform LogHeader
That's correct. The subform LogHeader is in the Detail Section of the main form. I see that the names are confusing. It's a bit late to change them all now...
How to pop open a detail form and then return to the record showing updates
The continuous form is always opened in the background. So I don't need to open it again.
me.requery
me.recordset.findfirst "primarykeyfield = " & ID
I use Forms!LogList.Requery. That works. but when I try to use Forms!LogList.recordset.findfirst I have an error message "can't find the field".
To my understanding, if the code runs on the editing form, if I use the Me.Requery it will requery the current form and the continuous form. The continuous form is not used for editing.
 

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
Sorry. I do not have the uncanny insights and clarity of thought of @Ebs17. I am way denser so help me out.
no worries I need long explanations to understand quickly ;)
Sorry. I do not have the uncanny insights and clarity of thought of @Ebs17. I am way denser so help me out.
1. Is your filter working to filter the continuous form or do you need help with that? If you need help what is your current code or query used to filter the subform
The filter runs well on the continuous form.
2. If the filter is working does the filter return more than one record? If it returns one record than I do not think the question about "focus" is relevant.
yes. Most of the time. And indeed, if not, there was no need for my question.
3. If the filter returns more than one record then what do you mean by the "currently updated record"? Are you working on a record in the continuous form then apply a filter and want to return to the same record?
The filters applied shall not change after the update of a specific record. But after scrolling to a specific record, editing it, I want to be able to see the modified record and not scroll back to it.
4. Where are you requerying? Do you mean after you apply the filter or do you requery somewhere in code?
I have a line of code "Forms!LogList.Requery" on the editing form that requeries the continuous form.
 

ebs17

Well-known member
Local time
Today, 08:44
Joined
Feb 7, 2020
Messages
1,946
The user could be updating or editing only one instance of the filtered list and not only one record. Thus the need to focus on the currently updated record.
Describe this in more detail. So far there has only been talk of implementing a filter for the display.

Records should have a unique ID. So if anyone edits records somewhere, they could/should remember these IDs. Then these can also be used in a filter.

If you only work in this subform, you will stay on the current record if you omit the requery. In the current form, the record only needs to be saved (in the table), the display should be up to date.
You would only need a requery for other displaying elements (forms, list fields, etc.).
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
@JoséBob
Bear with me this is my interpretation.
Interp.png

You have a main form that allows you to filter the subform
1 you apply a filter, in my case for the country
2 you get the filtered records, in my case for the country but more than a single record
3 You pop open your detail edit form somehow and make edits. In my case for the selected record ID 380

When you close the detail form it returns the continuous form back to the form you just edited, and shows updates. In my case returns to ID 380

Assumption
A. your filter of the subform works
B. you can pop open and edit in the detail form
C. you are asking how to return focus to the record you just edited

Again my code to do C. is as follows if that is what you are asking. I assume you are calling the popup from the subform

Code:
Public Function PopUpDetails()
  Dim currentID As Long
  currentID = Me.Id
  DoCmd.OpenForm "frmPopUpDetails", , , "ID = " & currentID, , acDialog
  Me.Requery
  Me.Recordset.FindFirst "ID = " & currentID

End Function

You have to use your real names here. Replace ID with the real name of the primary key. Replace frmPopUpDetails with real name of pop up form.


If I am still misinterpreting the ask, hopefully @ebs17 can enlighten us on what you are asking since he has unwavering insight into what OPs are asking.
 

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
@JoséBob
Bear with me this is my interpretation.
View attachment 111529
You have a main form that allows you to filter the subform
1 you apply a filter, in my case for the country
2 you get the filtered records, in my case for the country but more than a single record
3 You pop open your detail edit form somehow and make edits. In my case for the selected record ID 380

When you close the detail form it returns the continuous form back to the form you just edited, and shows updates. In my case returns to ID 380

Assumption
A. your filter of the subform works
B. you can pop open and edit in the detail form
C. you are asking how to return focus to the record you just edited

Again my code to do C. is as follows if that is what you are asking. I assume you are calling the popup from the subform

Code:
Public Function PopUpDetails()
  Dim currentID As Long
  currentID = Me.Id
  DoCmd.OpenForm "frmPopUpDetails", , , "ID = " & currentID, , acDialog
  Me.Requery
  Me.Recordset.FindFirst "ID = " & currentID

End Function

You have to use your real names here. Replace ID with the real name of the primary key. Replace frmPopUpDetails with real name of pop up form.


If I am still misinterpreting the ask, hopefully @ebs17 can enlighten us on what you are asking since he has unwavering insight into what OPs are asking.
Thanks for the little pictures: very helpful indeed.
You're right for most of the situation.
Using your picture:
on 3, I have a button "save". When I click on save, I want to see 2 updated (without closing 3) and the focus being on the record 380.
I tried ebs17's solution but it doesn't work (see code below). I have an error message "Run-Time error '2105': You can't go to the specified record". Could it be because the form 2 is in the background ?

Code:
intRecordID = Me.ID
Forms!Form2.Refresh
DoCmd.GoToRecord acDataForm, "Form2", acGoTo, intRecordID

And if I were to use your code, where should it run? as you're using "me": one "me" refers to the form 3 (currentID=Me.ID) and one "me" refers to the form 2 (Me.Requery). but maybe I'm wrong in my understanding.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:44
Joined
May 21, 2018
Messages
8,529
if you are in a form, say Form2 and want to do something to Form2
Instead of
Forms!Form2.Something you can
Me.Something

If calling Form2 from outside Form2 you have to reference it
Forms!Form2
or
Forms("Form2")
However you can never reference a subform by name. You have to reference it through the subform control. One reason is that you could have the form open in more than one subform control so which one would you be referring to.

If your save button is on the popup and you want to leave the popup open then probably need code like this in the save button

Code:
dim frm as access.form
me.dirty = false ' ensure the record is saved in the popup
Set frm = forms("loglist").nameOfSubFormControl.Form
frm.requery
frm.recordset.findfirst "ID = " me.ID

The name of the subform control on the main form is usually named the same as the source object (form) inside of it but not always
You need to replace ID with the correct name of the primary key (id) field if it is something different.

If you are leaving it open and you have real estate then I would make a split form. A list and the details on the same form. MS provides this functionality but it is problematic. Here is a better solution
 
Last edited:

JoséBob

New member
Local time
Today, 08:44
Joined
Sep 19, 2023
Messages
23
if you are in a form, say Form2 and want to do something to Form2
Instead of
Forms!Form2.Something you can
Me.Something

If calling Form2 from outside Form2 you have to reference it
Forms!Form2
or
Forms("Form2")
However you can never reference a subform by name. You have to reference it through the subform control. One reason is that you could have the form open in more than one subform control so which one would you be referring to.

If your save button is on the popup and you want to leave the popup open then probably need code like this in the save button

Code:
dim frm as access.form
me.dirty = false ' ensure the record is saved in the popup
Set frm = forms("loglist").nameOfSubFormControl.Form
frm.recordset.findfirst "ID = " me.ID

The name of the subform control on the main form is usually named the same as the source object (form) inside of it but not always
You need to replace ID with the correct name of the primary key (id) field if it is something different.

If you are leaving it open and you have real estate then I would make a split form. A list and the details on the same form. MS provides this functionality but it is problematic. Here is a better solution
Thanks.
It indeed workes.
The final line of code is following:
Code:
Forms!MainForm!SubForm.Form.Recordset.FindFirst "ID = " & intRecordID
I had an additional issue with the name of my forms which was not correct (beginner's mistakes, sorry...).
Thanks all for your time and support.
 

Users who are viewing this thread

Top Bottom