help referencing a form from a subform in vba

G

Gary

i have a subform called buttons on a form called sb.
when i click on a button on the buttons subform i want it to hide a
different suboform called salescreen on the sb form.

to clarify

SB = Main Form.
Buttons = Subform on SB.
Salesscreen = Subform on SB.

I thought i could just use something like the following code, for
the 'on click event' of a button on my buttons subform.

Forms!sb.salesscreen.Visible = "false"

it's not working thought, what am i doing wrong?


thanks as always.
Gary
 
N

Nikos Yannacopoulos

Gary,

Try this:

Me.Parent.Form.Controls("Salesscreen").Visible = False

or

Forms!SB.Controls("Salesscreen").Visible = False

HTH,
Nikos
 
B

Brendan Reynolds

Your syntax looks correct, but where you have 'sb' you need the name of the
subform *control* that contains the subform, rather than the name of the
subform itself. If you didn't explicitly name the control, it will have a
name something like 'ChildN' where 'N' is a number that depends on how many
other controls were already on the form when the subform control was
created.
 
B

Brendan Reynolds

Oops! I should have wrote "where you have 'salescreen'" not "where you have
'sb'".

Another possibility: In your post to the newsgroup, you refer to
'salescreen' and 'salesscreen'. It's an easy mistake to make. Could you have
the same mistake in your code?
 

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