VBA code to adjust Subform visible property

G

Guest

I am trying to make 2 subfroms alternate from being visible when a click a
button on one or the other. Using the following code--- Me.visible = False
--- Access says I can't hide a control that has the focus

When I sucessfuly move the focus to the other subform or main form and type:
subfrom1.visible = false Access says it can't find the control I am refering
to.

Access doesn't seem to have an easy way of refering to its subforms?
 
K

Ken Snell [MVP]

You must use the name of the subform control (the control that holds the
subform) when you want to make the subform invisible.

Me.SubformControlName.Form.Visible = False

Note that SubformControlName may or may not be the same as the name of the
Source Object (the form that serves as the subform).

While in design view, click on the very top of the subform and then read its
name from the Other tab of the Properties window.
 
D

Dirk Goldgar

James said:
I am trying to make 2 subfroms alternate from being visible when a
click a button on one or the other. Using the following code---
Me.visible = False --- Access says I can't hide a control that has
the focus

When I sucessfuly move the focus to the other subform or main form
and type: subfrom1.visible = false Access says it can't find the
control I am refering to.

Access doesn't seem to have an easy way of refering to its subforms?

It does, but you don't know it. <g>

On Subform1, the code to make Subform2 visible and hide Subform1 would
look like this:

With Me.Parent.Subform2
.Visible = True
.SetFocus
End With
Me.Visible = False

You have to make the other subform visible before you can set focus to
it, and you have to set the focus away from the active subform before
you can hide it.
 
D

Dirk Goldgar

James said:
I am trying to make 2 subfroms alternate from being visible when a
click a button on one or the other. Using the following code---
Me.visible = False --- Access says I can't hide a control that has
the focus

It occurs to me that one simple way to swap the visibilty of subforms is
to put each subform on a different page of a tab control, and then just
change pages on the tab control (which you can do programmatically by
assigning the PageIndex of the page you want to show to the Value
property of the tab control). If you don't want the user to be able to
change pages manually, you can set the tab control up with its Style
property set to None (no tabs or buttons)/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top