Set Focus on ComboBox on Subform (1 Viewer)

Malcolm17

Member
Local time
Today, 05:07
Joined
Jun 11, 2018
Messages
107
Hello,

Please can you help, I feel like I am missing something simple here. I am trying to click a button on a main form and then the subform is made visible and a combobox gets the focus on the subform to type in for a search. I'm using the following code, but what am I missing please?

Code:
Forms!frmBackGround.subfrmMaintenance.Form.cbxRoomSelect.SetFocus

My code for visible etc is not a problem, its just the Get Focus that I am struggeling with.

Thank you,

Malcolm
 

June7

AWF VIP
Local time
Yesterday, 20:07
Joined
Mar 9, 2014
Messages
5,474
Is subfrmMaintenance name of subform container control? I always name container different from the object it holds, like ctrMaint.

Code works for me.

Exactly what happens - error messsage, wrong result, nothing?
 

Malcolm17

Member
Local time
Today, 05:07
Joined
Jun 11, 2018
Messages
107
Sorry I'm not sure what you mean by container?

The main form is called frmBackGround
the subform is called subfrmMaintenance
and the combo that I would like to get focus is called cbxRoomSelect

Nothing happens. There is no error or anything.

I will have a look at the rest of the code tomorrow as there is quite a bit of it just incase something else is overriding it. It is on the head of a continuous form so this could be posing me an issue.

Thank you
 

June7

AWF VIP
Local time
Yesterday, 20:07
Joined
Mar 9, 2014
Messages
5,474
A subform is created by placing a subform/subreport container control on a form or report. This control has a SourceObject property which can reference a table, form, or report. If you simply drag a form or report onto another form or report, Access will create the container control automatically and set the SourceObject property. Access will name container same as the object it holds. I always name the container different.

Again, code works for me.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:07
Joined
Feb 19, 2002
Messages
43,293
The search combo needs to be unbound. I would not place it in the subform control. I would place it on the mainform. It takes up too much room being on every row of the subform.
 

June7

AWF VIP
Local time
Yesterday, 20:07
Joined
Mar 9, 2014
Messages
5,474
Pat, in subform header does not show on every row.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:07
Joined
May 21, 2018
Messages
8,529
My guess is your code is working but not giving you the results you expect. If the naming reference was wrong, you most likely would get some kind of an object defined error. It would not just "do nothing".
More likely it is setting the focus and then it immediately moves it off that control. This could happen due to a requery or code in another event, or other code in the click event that you are not showing. You may need a DoEvents before trying to set focus if you called other code that may cause a requery.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:07
Joined
May 7, 2009
Messages
19,245
set focus first on the Main Form.
next Setfocus on the subform.
lastly, setfocus on the control on the subform:

Code:
Forms!frmBackGround.SetFocus
Forms!frmBackGround!subfrmMaintenance.SetFocus
Forms!frmBackGround!subfrmMaintenance.Form!cbxRoomSelect.SetFocus
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:07
Joined
Feb 19, 2002
Messages
43,293
Pat, in subform header does not show on every row.
I didn't say anything about the subform header. I said to put the search box on the main form
 

June7

AWF VIP
Local time
Yesterday, 20:07
Joined
Mar 9, 2014
Messages
5,474
Pat, what did you mean by: "It takes up too much room being on every row of the subform."

OP has button in header of subform. You said to move it to header of main form for the above reason. My response is it will not be on every row of subform.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:07
Joined
Feb 19, 2002
Messages
43,293
"it" is the search box. I suppose if the subform is not DS view, you can include a header where you can put the search but whether you use a header in the subform or a header in the mainform is irrelevant. I usually have more space in the main form and would rather use that than add a row to the header of the subform. Subform headers tend to be one row tall. They just contain the column name above each column. So, to accommodate the search, you have to add a row above the column names.
 

Users who are viewing this thread

Top Bottom