Set Focus on ComboBox on Subform

Malcolm17

Member
Local time
Today, 04:45
Joined
Jun 11, 2018
Messages
114
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
 
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?
 
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
 
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.
 
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.
 
Pat, in subform header does not show on every row.
 
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.
 
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, 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
 
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.
 
"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

Back
Top Bottom