Disabling subform depending on mainform value (1 Viewer)

tb5038

Registered User.
Local time
Yesterday, 20:18
Joined
Jan 6, 2014
Messages
32
Hi,

I have a mainform called frm_Main containing the field AgeCalc

I then have a a subform which has some tabs, one of those tabs contains a subform called frm_Bans.

If the AgeCalc field is <17 I want to disable the subform frm_Bans.

Any ideas? Im a novice with coding but coping so far!

Thanks in advance
 

EternalMyrtle

I'm still alive
Local time
Yesterday, 20:18
Joined
May 10, 2013
Messages
533
In you main form in Design View go to the Event tab and in the OnCurrent select Event Procedure.

Now put in this:

Code:
If Me.AgeCalc[B]ControlName[/B]< 17 Then
Me.frm_Bans.Form.Visible = False
Else: Me.frm_Bans.Form.Visble=True
End If


For this to work properly you must use the control names so the name of the control on the form (go to Other tab and see the Name--change the name to something that makes sense).

BTW, I like to precede subforms with subfrm instead of frm since I have a ton of forms and it makes it easier.
 

tb5038

Registered User.
Local time
Yesterday, 20:18
Joined
Jan 6, 2014
Messages
32
Thanks for the tip about subform names.

Ive tried the code, works great. Only problem is the form I want to control is on a tabbed page within subform. does that make any difference?
 

Mihail

Registered User.
Local time
Today, 06:18
Joined
Jan 22, 2011
Messages
2,373
Only problem is the form I want to control is on a tabbed page within subform. does that make any difference?
No, but I think that will be ugly and annoying for the user to enter in that tab and to see... nothing.
So, in my opinion is better to hide the tab at all:
Code:
Me.TabCtlName.Pages(PageIndex).Visible = (Me.AgeCalcControlName>=  17)

'or

Me.TabCtlName.Pages("PageName").Visible = (Me.AgeCalcControlName >= 17)
The PageIndex is a number (integer) that is 0(zero) for the first page

Also, take a look here:
http://office.microsoft.com/en-us/access-help/using-the-tab-control-on-a-form-HA001230049.aspx

Good luck !
 

tb5038

Registered User.
Local time
Yesterday, 20:18
Joined
Jan 6, 2014
Messages
32
Hide the tab?! What a great idea! Thanks
 

Users who are viewing this thread

Top Bottom