Hide page upon opening

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like create a command button that
1. opens up a form
2. keeps one page visible
3. hides the remaining pages.

Yet my code seems to fail on the me.tabCtl1.pages(1).visible=true part. Any
thoughts?

Private Sub Command94_Click()
DoCmd.OpenForm "frmMain", acNormal
Me.TabCtl1.Pages(1).Visible = True
Me.TabCtl1.Pages(2).Visible = False
Me.TabCtl1.Pages(3).Visible = False
End Sub
 
Where is TabCtl1? If its on the form you just opened, "Me" refers to the
form where Command94 is, and that's not what you want.

HTH,
 
George,
Good point! As TabCtl1 is located on form: frmMain I can see how I went
down the wrong logic road. How would I go about referring to the correct
form . . . forms!frmMain.Pages(1).Visible = True?
 
The other thing you need to understand is that the index for the tabbed pages
start at 0 (zero) not at 1!
Assuming you want what shows up as Page1 visible when you open the form, your
code should be:

TabCtl1.Pages(0).Visible = True
TabCtl1.Pages(1).Visible = False
TabCtl1.Pages(2).Visible = False

That's right! Page1 is referred to as TabCtl1.Pages(0) in code!

Ain't Access just a barrel of laughs?
 
I have altered my code as suggested but something is still off. After I
click the command button, the form appears with all of the tabs. I then see
a Run Time error message (TabCtl1.Pages(0).Visible = True) that highlight the
VB code as a problem. Not sure what the problem is here. Any thoughts?
 
Brian,

Please post your code as it stands now so we can take another look at it in
the updated version...
 
Sorry, I didn’t mean for you to copy and paste those code lines as written; I
just used them to show you how the indices had to be referred to! If the
tabbed pages areon frmMain, and you’re setting their visibility from another
form, you need to reference them on frmMain:

forms!frmMain.TabCtl1.Pages(0).Visible = True
forms!frmMain.TabCtl1.Pages(1).Visible = False
forms!frmMain.TabCtl1.Pages(2).Visible = False
 
Not sure why I was thinking literally either. However, your suggestion works
like a charm. Much thanks!
 
Back
Top