Switching between subforms in a main form

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

Can anyone help me with a small glitch I've encountered
in Access XP?

In Access 2000, I was able to switch between subforms by
selecting a drop box in the main form using
the "AfterUpdate" function to hide/unhide similar to this:

me.form1.visible = false
me.form2.visible = true

In XP, I created a form with hidden subforms and instead
of using a drop box to show subforms, I'm trying to use a
text box and "OnClick" function. Problem is, I keep
getting a dialog box that says "You can't hide a control
that has focus." I've tried to reset the focus in
the "OnClick" function similar to this:

Forms!MainForm!TextField1.SetFocus
me.subfrm1.visible = false
me.subfrm2.visible = true

But I still get the same result. Can anyone show me a
way to switch focus from one subform to another?

Thanks in advance!
 
When you click the text box, it will have focus.
Where is the text box?

If it is in the main form, you should not have a problem.
If it is in the subform, you will have to SetFocus to something in the main
form and then toggle the visible property.

If the subform has a record that cannot be saved for some reason (e.g.
required field missing), you will need to deal with that before you can
change focus and hide the subform control.
 
Allen,

That's what I thought but that doesn't seem to be the
case. My text box resides on my main form which sits over
an option group but only for astetics, it serves no
function. It isn't working even though I tried to force
the focus change.

Any other suggestions?
 
There has to be something odd going on, e.g. perhaps this text box has the
name subfrm1?

Ask Access what is happening. In the Click event of your text box, at the
top of the event procedure, enter:
Debug.Print Screen.ActiveControl.Name
Stop
That should verify that the text box itself has focus in its Click event.

You can also try:
Debug.Print Me.subfrm1.ControlType
which should return 112 if it is a subform.

Hopefully that will take you on a useful path.
 
Back
Top