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

Setfocus on subform in tabbed pages

Status
Not open for further replies.

peterben

Programmer
Nov 20, 1999
7
GB
Under certain conditions as part of a validation procedure I want to use the Before Update event on a form to set the focus on a combobox that is on a subform, on a page, on a tab control, on a form.

I assume I need to setfocus on the tab control first, then the page, then the subform control and final the combobox.

Does anybody know the syntax to do this ?

Peterben
 
You should be able to set focus like this:

Forms!MainForm!SubformControlName.form!YourCombobox.SetFocus
 
Me![SubFrm_Name].Form![Ctrl_Name].SetFocus

Access will right the syntax for you most of the time. If while in design mode, open the form module for the before update event. In a blank area of the proceedure you are creating right click and select build. From there expand the forms section and select you top level form drill down the the sub-form or sub-sub-form find the control you wnat and click paste then OK. The syntax will be in the module. From there all you need to do in this case is add ".setfocus" and you ready to roll.

good luck
ssecca
 
Thanks FancyPrairie and ssecca for your speedy responses. I have tried both of your suggestions but as yet haven't got either to work. I have had no problem in the past with mainform/subform/combobox setfocus but with the tab control/pages I cannot get it to work. Any other ideas ????
 
Sorry! I'm at a lost. I've used tab controls several times (currently finished a form that had one) and didn't have a problem setting focus on a control within a subform. The tab control has nothing do with accessing the subform.

If you haven't already done so, use debug to figure out the syntax.
 
I think my problem was partly due to trying to setfocus in the 'Before Update Event'. I notice a
thread705-438569 "Setfocus doesn't work in After Update" may be a similar problem to mine.

To test my code out I have created a button on the form and used the following code in the OnClick event.

'First set the focus to the Control holding the subform
Forms!MainForm!subControl1.SetFocus

'Then set the focus to the control on the subform
Forms!MainForm!subControl1.Form.Controls!ComboBox.SetFocus

This code works. (The second line of code can be written in different ways.)

In investigating this problem I found an excellent Sample Library at and an example SubformReference2k.mdb which is well worth a look at for anybody with problems with accessing controls on subforms.

Thanks guys for your help...ssecca ...Using Expression Builder to check syntax is an excellent idea. You are correct FancyPrairie the tab control has nothing to do with accessing the subform.

Peterben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top