Refer to Control within a Tab Control in VBA (1 Viewer)

FranD

Registered User.
Local time
Today, 19:06
Joined
Feb 29, 2000
Messages
32
I have a form which contains several controls, including command buttons and one subform. There is quite a bit of code in place to validate the data. Unfortunately, so many fields have been added that I now need to use a tab control with two tabs - I've divided the data entry fields between these two tabs. The problem is now a lot of my code isn't working. It can't find the controls referred to in the code - I presume because it's now located on the tab control.

So I guess what I need to know is how to refer to these controls now in code - as well as the subform!!!!

I'm holding up our Charge Entry Unit while I try to figure this out. If anyone could help, I'd be enormously grateful!!
 

Matthew Snook

NW Salmon Database
Local time
Today, 19:06
Joined
Apr 19, 2001
Messages
133
Fran:

I looked through my project but I couldn't find exactly what you want. I use this to set the date on a popup form to match the date of a main form:

Me.Event_Date = Forms![frm_Fish_ ID]!frm_Pathology.Form![Event_Date]

it refers to a control which is on a subform which is on a tab. In this case "frm_Fish_ID" is the main form; there is a tab control named "TabCtl142" (I guess I just left the default name in place); a page (tab) on that control called "&Pathology"; a subform on that page called "frm_Pathology"; a tab conrol on THAT form called "TabCtl196"; a page on the tab control called "&General"; and a control on that page called "Event_Date". Whew!

But the line of code I gave you only used the main form, subform, and control name to reference the field. A reference to the page or tab or the tab control itself is apparently not necessary. Hope that helps.

Matt

[This message has been edited by Matthew Snook (edited 01-11-2002).]
 

boblarson

Smeghead
Local time
Today, 11:06
Joined
Jan 12, 2001
Messages
32,059
I use tabbed controls alot. As long as your code is located in the Form's module it is easy. Just use the control name that you have. However to select a tab in code, do this:

(I like to name my tab control something simple like tabInterface)

Me.tabInterface.Pages(1).SetFocus

Remember that the first page is index 0 and then page 2 would be 1, etc.

That is how you navigate through the individual tab pages via code.

As for referencing controls IN the tabs, just use the control's name. However, make sure you name your controls something OTHER than the exact name of your table field. It doesn't like it to have the ambiguous naming. So for a field in your table that's titled FirstName use txtFirstName for a text box or something that will be more to the programming "standards."

Good luck and let me know if you need additional help with the tab control. I personally love it and it makes fitting things on one form extremely easy!

BL
hth
 

spaceace507

New member
Local time
Today, 13:06
Joined
Feb 18, 2009
Messages
1
along the lines of this thread, if the page in the tabcontrol contains a subform, can i use that subform's controls without explicit reference to the subform? eg, something like tabctl1.Pages(selectedTabIndex).???.TextBoxName rather than SubFormName.TextBoxName

I have a tabcontrol with several tabs containing subforms that are very similar, but have distinct parent forms. But each of these subforms has 1 set of comboboxes that is the same in all of them (I am capturing data at several timepoints).

I'd like to write 1 block of code which detects the selected tab, and then hides or displays several comboboxes in the subform in that selected tab.

I've tried:

TabCtl2.Pages(TabCtl2.Value).Form.Type_of_infection.Visible = False

where Type_of_infection is the name of the combo box I want to hide, but I get an error:
Compile Error: Method or data member not found

which also happens if i leave out the ".Form". Can I get the Page in the TabControl Pages collection to return the subform object, and then I can manipulate the combo box in that object?

Any help or suggestions would be greatly appreciated.

Joe
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 19:06
Joined
Sep 12, 2006
Messages
15,744
generally speaking its better not to manipulate objects on subforms from the main form

in theory the subform should be "self aware", as it aware, and not need managing from the main form - otherwise it sounds like a normalisation issue.

what are you needing to change on the subform?

---------
having said that, if a subform is in a control named say, subdetails

you can just use subdetails!controlname to refer to a subforms controls
 

boblarson

Smeghead
Local time
Today, 11:06
Joined
Jan 12, 2001
Messages
32,059
Also, you don't refer to a tab control at all when dealing with items on it. You only really need to refer to it if you are wanting to select a tab or figure out which tab was selected. Otherwise you just refer to the object just as if it wasn't on a tab control.
 

campo88

Registered User.
Local time
Today, 19:06
Joined
Nov 20, 2009
Messages
46
Hi

I have a similar question which I hope can be answered in this thread.


In page 2 of my tab control, I have 2 combo boxes. The second combo box needs to be linked so that its list depends on what option is selected from the first combo box. How can I do this?

I have done this in a form, however when putting it into a tab control page, it does not work. When I try to change the selection from combo box 1, combo box 2 does not requery.

Hope you can help.
 

JANR

Registered User.
Local time
Today, 20:06
Joined
Jan 21, 2009
Messages
1,623
Tabed pages is still a control on the parent form so you can refrence it the same as if was on a normal form. see this link: http://www.mvps.org/access/forms/frm0025.htm

So Me!NameOfControl.Requery should work even if this control is located on a tabed page.

JR
 

oldes

New member
Local time
Today, 22:06
Joined
May 28, 2011
Messages
9
Hi FranD (and All)

When you cut and past controls on tabs Access do not carry the events references which were previously created...

When it happens I Cut the source code from the Form module, save the blanked module, and paste the code and re save it again..

when you paste a event code, VBA tries to (re)bind with relevant controls...

I hope it works...
Kind regards
 

vengsiva

Registered User.
Local time
Today, 23:36
Joined
Jan 9, 2004
Messages
31
Good luck and let me know if you need additional help with the tab control. I personally love it and it makes fitting things on one form extremely easy!

BL
hth
I have a form with a combo and a pivot chart in a page control.Can i filter the rowsource of the pivot chart on the value selected in combo?
vengsiva
 

Users who are viewing this thread

Top Bottom