open form2 on a specific tab from form1 (1 Viewer)

patkeaveney

Registered User.
Local time
Today, 04:40
Joined
Oct 12, 2005
Messages
75
Hi All

I have a command button on form one which opens form 2. (works ok)
Form 2 has tabs on it (one called tabdepts)

Is there a way to open form2 with the tabdepts displayed.

Note: Form2 is not open at this point.


Thanks

Pat
 

Mr. B

"Doctor Access"
Local time
Yesterday, 22:40
Joined
May 20, 2009
Messages
1,932
If you just want to have the "tabdepts" tab to be selected when form2 opens, then make the "Page Index" property for the "tabdepts" tab to be (0) zero. You may also want to change the "Page Index" property for your other tabs so they will be in the order you would like them to be.

If, on the other hand, you want to be able to specify which tab is displayed when the form open based on some info or data, that will require some coding but is can be done.

Please post back with any questions.
 

patkeaveney

Registered User.
Local time
Today, 04:40
Joined
Oct 12, 2005
Messages
75
Mr B

Thanks for your reply. I need option 2.
When form2 is opened from form1 I need the tabdepts displayed.

When form 2 is opened from other forms it needs to open at tab 0 as you mention in option 1 of your reply.

Pat
 

Mr. B

"Doctor Access"
Local time
Yesterday, 22:40
Joined
May 20, 2009
Messages
1,932
I have a command button on form one which opens form 2.

In your original post you had only indicated that you were trying to open form 2 (where the tab control is) from form one. That is why I suggested that you could just change the "Page Index" property to force the desired tab to be displayed when form 2 opened.

Specifying a specific tab to be presented when opened from a form poses a different problem.

First, you will need a way to pass information from the form that is opening form 2 to indicate which form opened form 2. You can do this by using the "OpenArgs" argument of the docmd.openform method. like this:

Code:
DoCmd.OpenForm "Form2",,,,,, "Form1"

This line of code would be in the Click Event of the command button on "Form1". (You would change the "Form1" to any value that would be an indicator that "Form1" is opening "Form2" Obviously, you will need to use this same line of code from a command button on "Form3", passing a value that indicates that "Form3" opened "Form2".

Next, you will need VBA code in the On Open event of "Form2" that will evaluate which form called or opened "Form2". I get the impression that there may be multiple forms that would be calling or opening "Form2" and not just a couple. If this is the case, I would use a "Select Case" to do this type of evaluation. Like this:

Code:
Select Case Me.OpenArgs
     'create a "Case" statement for each value that will be 
     'passed using the "OpenArgs" argument in the "OpenForm" method
     Case "Form1"
          'Set focus to the tab that you want to display, using the 
          'Page Index" property of that tab or page
          Me.TabCtl0.Pages(0).SetFocus
     Case "Form3"
          Me.TabCtl0.Pages(2).SetFocus
     Case Else
          'the "Else" statement can be used here if you have multiple forms
          'that you need to display a default tab or page. In this case you
          'would not pass any value in the "OpenArgs" argument (just leave
          'it blank)
          Me.TabCtl0.Pages(1).SetFocus
     'you can have as many "Case" statements as you need
End Select

Each tab (page) of a tab control has a unique "Page Index" property.

In the code above you are simply using VBA code to specify the tab or page of the tab control will be displayed (have the focus).
 

patkeaveney

Registered User.
Local time
Today, 04:40
Joined
Oct 12, 2005
Messages
75
Thanks

The open arguments solution is exactly what i needed.

I have never used that before so again thank you very much

Pat
 

Mr. B

"Doctor Access"
Local time
Yesterday, 22:40
Joined
May 20, 2009
Messages
1,932
You are quite welcome, Pat.

Glad to help.

Good luck with your project.
 

Users who are viewing this thread

Top Bottom