SetFocus Tab Control Page (1 Viewer)

damian

Registered User.
Local time
Today, 02:14
Joined
Jun 27, 2004
Messages
87
Hi

Been struggling for a couple of days now, I want to reference a page called Completion on a tab control (TabCtl220) on a form called permittoworkform and select it - all this from a button on another form.

I don't want to put any code in the OnLoad event, for example, as I'd like to have other buttons linking to different pages on the same tab control of this form.

Been trying the following code behind click event of a label on my 'Switchboard' form:

DoCmd.OpenForm "permittoworkform"
'Forms!permittoworkform.TabCtl220.Pages("Completion").SetFocus

Error states: Method item of object Forms failed

Any assistance would be welcomed
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:14
Joined
Jan 20, 2009
Messages
12,851
Forms!permittoworkform.TabCtl220.Pages("Completion").SetFocus

Try this:

Forms!permittoworkform.TabCtl220.Completion.SetFocus

http://msdn.microsoft.com/en-us/library/bb243813.aspx

Because each page is a member of the form's Controls collection, you can refer to a page solely by its Name property without referring to the tab control's name or its Pages collection. For example, to change the value of the Caption property of a page with its Name property set to Page1, use the following statement:
Page1.Caption = "First Page"
 

damian

Registered User.
Local time
Today, 02:14
Joined
Jun 27, 2004
Messages
87
Thanks for the very prompt feedback - I've adjusted code a little but still get errors. I think it'll be down to the permittoworkform being opened, taking focus and the second line of the code failing?
 

damian

Registered User.
Local time
Today, 02:14
Joined
Jun 27, 2004
Messages
87
Had a further complication with the well documented 'OLE Server or ActiveX control' error but have imported everything into a new db and have appeared to have resolved that one - however still unable to setfocus on a specific page of the tab control
 

SOS

Registered Lunatic
Local time
Yesterday, 18:14
Joined
Aug 27, 2008
Messages
3,517
however still unable to setfocus on a specific page of the tab control
Just set the value of the index to the main tab control (control which has all of the tabs on it):

Code:
Forms!permittoworkform.TabCtl220 = 2

I used 2 (third page) but you can use whatever value the index is for the page you want.
 

damian

Registered User.
Local time
Today, 02:14
Joined
Jun 27, 2004
Messages
87
Star man - it worked!!!

Thank you for your time
 

BrankoG

New member
Local time
Today, 03:14
Joined
May 29, 2009
Messages
7
I apologize for hijacking this thread, but I have exactly the same problem, but still cannot get it to work.

I am modifying Contact Management Database template, and have several tabs (pages)in tab control on Contact Details form. I would like to set that when users click on the New Contact in the main form, Contact Details form is opened with second tab active.

I have tried suggested solution and many other variations, but it is not working the way I set it up. What I have on the New Contact button is original macro that opens blank form. If I add RunCode to the macro and call function that has only one line (Forms![Contact Details].tabContacts=1) it does nothing until the form is closed and then reports that form cannot be found.

I know that the line works, because I set up a test button on the form Contact Details itself with that function, and it works great.

Does anybody have an idea what I am doing wrong?

Regards,
BrankoG
 

damian

Registered User.
Local time
Today, 02:14
Joined
Jun 27, 2004
Messages
87
Could you post a copy of what you've got so far - sounds like a referencing issue and you'll gather from my post I'm no expert but I'll give it a go.
 

Spidergoy

New member
Local time
Yesterday, 22:14
Joined
Oct 10, 2019
Messages
3
Just set the value of the index to the main tab control (control which has all of the tabs on it):

Code:
Forms!permittoworkform.TabCtl220 = 2

I used 2 (third page) but you can use whatever value the index is for the page you want.

Hi: I have the same problem but when I execute the code (asigning a value to the tab control) I get a message "Cant assign a value to this object". Why is this ?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:14
Joined
Feb 19, 2002
Messages
43,233
The tab control is not in the reference hierarchy of a form's objects. So, to reference a field on a form:

Forms!someform!somefield

To reference a field on a subform

Forms!someform!subform.form!somefield

The tab control is not involved at all.

Keep in mind that when referencing formA from formB, formA MUST be open and you will ALWAYS be referencing the current record whatever that it. Same for a subform, it must be loaded (this is problematic when the subform is sitting on a Navigation form) and you will be referencing whatever record Access thinks is current.

If you need a single value, the simplest solution is to pass it in the OpenArgs when formA opens formB. That method has the advantage when multiple forms might open formB since formB gets its variable from the OpenArgs rather than having to reference what ever form opened it.
 

Spidergoy

New member
Local time
Yesterday, 22:14
Joined
Oct 10, 2019
Messages
3
Thanks Pat, I wish you were right. But no, access forces you to use the common subnavigation control instead of the specific subform name. if you use the real subform name it gives you an error. When you use the generator to let access build the reference, even if you select the a subform field it will build the string using the the subnavigation control. Really strange.
 

Users who are viewing this thread

Top Bottom