Open form to third tab

  • Thread starter Thread starter Doctor
  • Start date Start date
D

Doctor

From one form button, I want to open to a another form on a specific tab.
I've tried to figure this out, but to no avail.

In form RegionalCompetitions, I have a button that I want the user to click
to open another form called ChurchInformation. ChurchInformation has 6 tabs.

I am trying to use OpenArgs, but I just can't seem to get it right.

Here is what I have for the button in RegionalCompetitions:

Private Sub Contact1_Click()
On Error GoTo Err_Contact1_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
stLinkCriteria = "[ContactID]=" & Me![RHostContact]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "2" !!!!!!The "2"
(two) is supposed to be for the value that I want to send to the
ChurchInformation form because I want to open the third tab!!!!!!!!
Exit_Contact1_Click:
Exit Sub
Err_Contact1_Click:
MsgBox Err.Description
Resume Exit_Contact1_Click
End Sub


As far as the code for the ChurchInformation form, I have tried so many
variations and none have worked. so it is pointless to post that here.
Even more, I don't know which property I should put the code in? The OnOpen
or OnLoad?

I think what this all boils down to is that I have no understanding of the
OpenArg's principles. However, I have even tried to code in for the
ChurchInformation form to always open to the third tab and I was even
unsuccessful at that.

Please Help!

Thanks in advance.
 
You need to use the tabCtl for the form you're opening. Personally, I'd place
the desired tab number into a PUBLIC variable, then, on the new form's "On
Activate" event, set the 'tabCtl' to the value in the public var. Works like
a charm.
 
Thanks for the fast reply!

I'm so new to VB. Where and how do I code your idea?

First, where do I place the public variable and how do I code it.

Then, to make sure you understand my question, I don't want the form to open
to the third tab everytime...only when the button in the first form is
clicked. I think that's what you meant. just wanted to be sure.
 
Some of the other guys will probably have a different answer than I gave, but
I'm a control-freak, and want to know EXACTLY what's going on, and be in
total control over my code.

Create a new Module (you can name it anything you want, but I ususally use
"globalDefs"). In that module, code the following:

Public WhateverVariableNameYouWant as Integer

Save the module.

In your button click code, use thise:

WhateverVariableNameYouWant = 2

then issue your open-form command.

In the On Activate event for the newly opening form, use this code:

Me.TabCtlXXX = Nz(WhateverVariableNameYouWant)

That'll do it. NOTE: The "XXX" I specified in the TabCTL above will vary by
application (It's just a control number after all, so you'll need to know its
number in order to reference it properly.)

It's like specifying a control called "Text24" for example.

Good luck.

BTW, this method will work fine for users not clicking the button. When your
application first opens, the value will be zero (NULL actually, which the Nz
will trap and set to zero, which will open the form to the first tab). The
LAST THING you should do whenever you close that form is to set:

WhateverVariableNameYouWant = 0

which will clear it.
 
First, avoid public variables. They have many problems.

The easiest way is to use the Form Load event and set the focus to the page:

Me.MyTabControl.Pages(2).SetFocus

Using 2 will set the focus to the 3rd page, the page collection index is
zero based. That is, the first page is .Pages(0)
 
I did not read the entire post, sorry, here is the amended code

First in the button Click event, pass a string value to the form in the
OpenArgs argument.

DoCmd.OpenForm "MyFormName", , , , , ,"Yes"

Then, in the Load event:

If Me.OpenArgs = "Yes" Then
Me.MyTabControl.Pages(2).SetFocus
End If
 
See? Told ya that someone would come up with a different method.

Klatuu, you dan man (?)

;^)
 
Great! This is what I am looking for.

Error: it is giving an error on MyTabControl.

Is this supposed to stand for something? Am I supposed to put the name of
the page in this place?

Almost there.
 
Back
Top