Moving focus to an invisible subform

rw0706

Registered User.
Local time
Today, 13:45
Joined
Mar 25, 2009
Messages
10
Hi,

The main form is set to on current making the subform visible = false. Upon pressing an option box the subform becomes visible. I would also like the focus to move to the subform at this same time but am getting a runtime error 2110, I believe. Access doesn't like moving focus to something that is invisible, but I want the subform to gain focus as soon as it becomes visible.

Any help is greatly appreciated,
Thanks.
 
You can try something like this:
Code:
if Me.Child0.Form.visible = true then Me.Child0form.setfocus

With this approach, the setfocus command will not execute unless the suform is visble
 
Alternatively if you really need to set the focus to the subform

Code:
Me.Child0.Form.visible = true 
Me.Child0.Form.setfocus
 
Thanks Steve and Rabbie! I ended up doing this and it works like a charm (knocks on wood).

Code:
Me.tblMeasurement_subform.Visible = True
Me.tblMeasurement_subform.SetFocus
 
One more thing: how do I set the focus to a control in the subform, called 'black'. The above works for getting the control to the subform, and the first control in the subform is called black. Then then next 4 fields are filled by a measurement system that has a macro set up so that it auto tabs.

My problem is that sometime, by mistake, workers are clicking one of the other fields. Then they go to the next record and evantually when focus is set to the subform on the next record it goes to the field they last clicked on, not the first one (in datasheet mode)
 
To set focus on a control of a subform requires 2 steps:

Me!MySubForm.SetFocus
Me!MySubForm.Form!MyControl.SetFocus
 
To set focus on a control of a subform requires 2 steps:

Me!MySubForm.SetFocus
Me!MySubForm.Form!MyControl.SetFocus

I'm not 100% sure but I suspect that;

Code:
Me!MySubForm.SetFocus
is redundant, you should just need
Code:
Me!MySubForm.Form!MyControl.SetFocus
 
The following is from Access 2003 VBA help. Perhaps 2007 is different?

You can use the SetFocus method to move the focus to a subform, which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.

Evan
 

Users who are viewing this thread

Back
Top Bottom