Subform visibility

Joy Gomez
Joy Gomez used Ask the Experts™
on
Hello,

I have a main form (Main_Menu) and 2 sub forms (Main_DLMP and Main_DeptView). In the main menu I have 2 labels that act as menu.  I have click events on both these labels.  I want to make one visible, and the other not visible.  But I struggling with this.  These are the 2 events I have for each of the labels in my main form.

 This is the event on the first label. As default Main_DLMP visibility is set to True and DLMP_DeptView is set to False.
    Forms![Main_Menu].[Main_DLMP].SetFocus
    Forms![Main_Menu]![Main_DLMP].Form.Visible = True
    Forms![Main_Menu]![Main_DeptView].Form.Visible = False

This is the event on the second lablel
    Forms![Main_Menu].[Main_DeptView].SetFocus
    Forms![Main_Menu]![Main_DeptView].Form.Visible = True
    Forms![Main_Menu]![Main_DLMP].Form.Visible = False
   
I am getting an error on the second label... Cannot set focus.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You have to make it visible BEFORE you can set focus.
So reverse the order so it becomes:
Forms![Main_Menu]![Main_DeptView].Form.Visible = True
Forms![Main_Menu].[Main_DeptView].SetFocus
Forms![Main_Menu]![Main_DLMP].Form.Visible = False

Open in new window


And you should hide the subform object, not the form, so it then becomes:
Forms![Main_Menu]![Main_DeptView].Visible= True
Forms![Main_Menu].[Main_DeptView].SetFocus
Forms![Main_Menu]![Main_DLMP].Visible = False

Open in new window

John TsioumprisSoftware & Systems Engineer

Commented:
Normally Labels don't need Focus...
What you probably need is that the Labels are unassociated with any controls. To check it just right clicks -->Properties..check if Events are displayed...if its blank ..then the easy way is to make a copy of the Label delete the old Label..rename the New label to match the old name and you should be fine
Also for Visiility
Me.Lbl1.Visible = Not Me.Lbl2.Visible

Open in new window

John TsioumprisSoftware & Systems Engineer

Commented:
Probably i confused Labels with Subforms..
Ok np
On the click event of Labels...
Form_NameOfSubForm1.Visible = Not Form_NameOfSubForm2.Visible

Open in new window

Author

Commented:
Thank you Anders... worked great!

John... thanks for your continuous support.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial