Navigating Tab pages

M

magmike

I'd like to have one button that the user can use to keep "flipping"
pages in order in a tab control. Is there a way to call up in the code
which page in the tab group has the focus, so that the next can be
focused when the button is clicked? Preferably this button would not
be on the tab control itself.

Thanks in advance!
magmike
 
J

John Spencer

The vba code would look like the following

Private Sub btnChangeTab_Click()
Dim iTab As Integer

iTab = Me.TabCtL.Pages.Count - 1

If Me.TabCtL = iTab Then
Me.TabCtL = 0
Else
Me.TabCtL = Me.TabCtL + 1
End If
End Sub


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
K

Klatuu

In the Click event of your button:

If Me.MyTabControl < Me.MyTabControl.Pages.Count - 1 Then
Me.MyTabControl = Me.MyTabControl + 1
Else
Me.MyTabControl = 0
End If

This will move to the next page until it reaches the last page, then it will
move back to the first page.
 
M

magmike

In the Click event of your button:

    If Me.MyTabControl < Me.MyTabControl.Pages.Count - 1 Then
        Me.MyTabControl = Me.MyTabControl + 1
    Else
        Me.MyTabControl = 0
    End If

This will move to the next page until it reaches the last page, then it will
move back to the first page.







- Show quoted text -

Awesome - thanks both of you. I'm creating my own tabs using labels.
To change to the look (back color, text color, border color) of the
active tabs label - I'm thinking it best to use onCurrent of the tab
control to determine which page is active and then set the properties
of said label control. What is the most efficient way to do this?

Thanks in advance,
magmike
 
K

Klatuu

Use the tab control's change event.
It fires whenever you move to a different tab.
Now I have not tested this particular thing.
For some controls, some events do not fire if something is done
programmatically. They only fire if you do it manually. For example, when
a user types a value in a text box, the after update event fires, but if in
VBA code, you assign a value to a text box, its after update event does not
fire, so you had better test that before you go too far with it.

In the Click event of your button:

If Me.MyTabControl < Me.MyTabControl.Pages.Count - 1 Then
Me.MyTabControl = Me.MyTabControl + 1
Else
Me.MyTabControl = 0
End If

This will move to the next page until it reaches the last page, then it
will
move back to the first page.







- Show quoted text -

Awesome - thanks both of you. I'm creating my own tabs using labels.
To change to the look (back color, text color, border color) of the
active tabs label - I'm thinking it best to use onCurrent of the tab
control to determine which page is active and then set the properties
of said label control. What is the most efficient way to do this?

Thanks in advance,
magmike
 
M

magmike

Use the tab control's change event.
It fires whenever you move to a different tab.
Now I have not tested this particular thing.
For some controls, some events do not fire if something is done
programmatically.  They only fire if you do it manually.  For example, when
a user types a value in a text box, the after update event fires, but if in
VBA code, you assign a value to a text box, its after update event does not
fire, so you had better test that before you go too far with it.








Awesome - thanks both of you. I'm creating my own tabs using labels.
To change to the look (back color, text color, border color) of the
active tabs label - I'm thinking it best to use onCurrent of the tab
control to determine which page is active and then set the properties
of said label control. What is the most efficient way to do this?

Thanks in advance,magmike- Hide quoted text -

- Show quoted text -

One more thing - When This button is pushed, I'd like it to go to a
specific page in the tab control and then after that "flip" through
the pages. I've tried the following and it is not working - it just
tabs between pages 1 and 2.

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1
Else: Me.Tabs = 0
End If
Else: Me.Tabs = 1
End If
End Sub

Any ideas?

thanks in advance - magmike
 
K

Klatuu

I don't follow your statement. How will the button code know which page you
want to go to? and when to go to that page and when to flip?

If you define what you want, I can help.

As to the problem with your code.
First 0 is the first page, not 1, so I don't know what you really intend
here

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then >> you are on the second page
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1 >> Never executes you have > 2 pages
Else
Me.Tabs = 0 >> Always executes and returns to first page
End If
Else
Me.Tabs = 1 >> returns you to the second page
End If

End Sub

Use the tab control's change event.
It fires whenever you move to a different tab.
Now I have not tested this particular thing.
For some controls, some events do not fire if something is done
programmatically. They only fire if you do it manually. For example, when
a user types a value in a text box, the after update event fires, but if
in
VBA code, you assign a value to a text box, its after update event does
not
fire, so you had better test that before you go too far with it.








Awesome - thanks both of you. I'm creating my own tabs using labels.
To change to the look (back color, text color, border color) of the
active tabs label - I'm thinking it best to use onCurrent of the tab
control to determine which page is active and then set the properties
of said label control. What is the most efficient way to do this?

Thanks in advance,magmike- Hide quoted text -

- Show quoted text -

One more thing - When This button is pushed, I'd like it to go to a
specific page in the tab control and then after that "flip" through
the pages. I've tried the following and it is not working - it just
tabs between pages 1 and 2.

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1
Else: Me.Tabs = 0
End If
Else: Me.Tabs = 1
End If
End Sub

Any ideas?

thanks in advance - magmike
 
M

magmike

I don't follow your statement.  How will the button code know which page you
want to go to? and when to go to that page and when to flip?

If you define what you want, I can help.

As to the problem with your code.
First 0 is the first page, not 1, so I don't know what you really intend
here

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then   >> you are on the second page
    If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
        Me.Tabs = Me.Tabs + 1 >> Never executes you have > 2 pages
    Else
        Me.Tabs = 0  >> Always executes and returns to first page
    End If
Else
    Me.Tabs = 1  >> returns you to the second page
End If

End Sub









One more thing - When This button is pushed, I'd like it to go to a
specific page in the tab control and then after that "flip" through
the pages. I've tried the following and it is not working - it just
tabs between pages 1 and 2.

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then
    If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
        Me.Tabs = Me.Tabs + 1
        Else: Me.Tabs = 0
    End If
    Else: Me.Tabs = 1
End If
End Sub

Any ideas?

thanks in advance -magmike- Hide quoted text -

- Show quoted text -

In truth, this is more exercise than reality - I was trying to make
sense of the logic and obviously failed. That said - the initial goal
was to have the click of this particular object (a label) send focus
to the 2nd page in the tab control (Me.TabControl = 1). Then I started
thinking, it would be cool (since I am always finding ways to be more
lazy!), if, instead of having to move the cursor with the mouse to
each tab and click to navigate through the tabs, what if the user
could just keep clicking on the same object (in this case, a label) to
do so. You helped me with that. However, that circumvented the initial
goal. Now, if the tab control was currently focused on the fourth page
(Me.TabControl = 3), then clicking on the object would have to happen
through the four remaining pages, as well as the first page, before
getting to the second page - the initial goal of the object (defeating
the lazy part!). So here I was trying to choose between features - and
hoping I could figure out how to have my cake and eat it too.

I hope that makes a little more sense to you. Does it?

magmike
 
L

Larry Kahm

Alternatively you could have a text box called JumpTo and have the user
enter the number of the tab (limited to the number of tabs you have in your
display) they want to go to.

They type in 3 and you trigger the AfterUpdate event. You subtract 1 from
the number they entered and set the tabcontrol to tab 3. Is that what you
wanted, in a lazy kind of way?

Larry

I don't follow your statement. How will the button code know which page
you
want to go to? and when to go to that page and when to flip?

If you define what you want, I can help.

As to the problem with your code.
First 0 is the first page, not 1, so I don't know what you really intend
here

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then >> you are on the second page
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1 >> Never executes you have > 2 pages
Else
Me.Tabs = 0 >> Always executes and returns to first page
End If
Else
Me.Tabs = 1 >> returns you to the second page
End If

End Sub









One more thing - When This button is pushed, I'd like it to go to a
specific page in the tab control and then after that "flip" through
the pages. I've tried the following and it is not working - it just
tabs between pages 1 and 2.

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1
Else: Me.Tabs = 0
End If
Else: Me.Tabs = 1
End If
End Sub

Any ideas?

thanks in advance -magmike- Hide quoted text -

- Show quoted text -

In truth, this is more exercise than reality - I was trying to make
sense of the logic and obviously failed. That said - the initial goal
was to have the click of this particular object (a label) send focus
to the 2nd page in the tab control (Me.TabControl = 1). Then I started
thinking, it would be cool (since I am always finding ways to be more
lazy!), if, instead of having to move the cursor with the mouse to
each tab and click to navigate through the tabs, what if the user
could just keep clicking on the same object (in this case, a label) to
do so. You helped me with that. However, that circumvented the initial
goal. Now, if the tab control was currently focused on the fourth page
(Me.TabControl = 3), then clicking on the object would have to happen
through the four remaining pages, as well as the first page, before
getting to the second page - the initial goal of the object (defeating
the lazy part!). So here I was trying to choose between features - and
hoping I could figure out how to have my cake and eat it too.

I hope that makes a little more sense to you. Does it?

magmike
 
K

Klatuu

You can set up tab controls so there are no tabs showing, so what you are
after is not entirely unreasonable. Just thinking off the top of my head
and incorporating Larry Hahm's suggestion, you could set up two small
command buttons with a small text box between them - much like the Access
navigation buttons - with left and right arrows.

Then you could display the current page number in the text box and allow the
user to move forward and back using the command buttons or jump to a
specific page using the text box.

I don't follow your statement. How will the button code know which page
you
want to go to? and when to go to that page and when to flip?

If you define what you want, I can help.

As to the problem with your code.
First 0 is the first page, not 1, so I don't know what you really intend
here

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then >> you are on the second page
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1 >> Never executes you have > 2 pages
Else
Me.Tabs = 0 >> Always executes and returns to first page
End If
Else
Me.Tabs = 1 >> returns you to the second page
End If

End Sub









One more thing - When This button is pushed, I'd like it to go to a
specific page in the tab control and then after that "flip" through
the pages. I've tried the following and it is not working - it just
tabs between pages 1 and 2.

Private Sub DataLabel_Click()
If Me.Tabs = 1 Then
If Me.Tabs < Me.Tabs.Pages.Count - 1 Then
Me.Tabs = Me.Tabs + 1
Else: Me.Tabs = 0
End If
Else: Me.Tabs = 1
End If
End Sub

Any ideas?

thanks in advance -magmike- Hide quoted text -

- Show quoted text -

In truth, this is more exercise than reality - I was trying to make
sense of the logic and obviously failed. That said - the initial goal
was to have the click of this particular object (a label) send focus
to the 2nd page in the tab control (Me.TabControl = 1). Then I started
thinking, it would be cool (since I am always finding ways to be more
lazy!), if, instead of having to move the cursor with the mouse to
each tab and click to navigate through the tabs, what if the user
could just keep clicking on the same object (in this case, a label) to
do so. You helped me with that. However, that circumvented the initial
goal. Now, if the tab control was currently focused on the fourth page
(Me.TabControl = 3), then clicking on the object would have to happen
through the four remaining pages, as well as the first page, before
getting to the second page - the initial goal of the object (defeating
the lazy part!). So here I was trying to choose between features - and
hoping I could figure out how to have my cake and eat it too.

I hope that makes a little more sense to you. Does it?

magmike
 
M

magmike

You can set up tab controls so there are no tabs showing, so what you are
after is not entirely unreasonable.  Just thinking off the top of my head
and incorporating Larry Hahm's suggestion, you could set up two small
command buttons with a small text box between them - much like the Access
navigation buttons - with left and right arrows.

Then you could display the current page number in the text box and allow the
user to move forward and back using the command buttons or jump to a
specific page using the text box.















In truth, this is more exercise than reality - I was trying to make
sense of the logic and obviously failed. That said - the initial goal
was to have the click of this particular object (a label) send focus
to the 2nd page in the tab control (Me.TabControl = 1). Then I started
thinking, it would be cool (since I am always finding ways to be more
lazy!), if, instead of having to move the cursor with the mouse to
each tab and click to navigate through the tabs, what if the user
could just keep clicking on the same object (in this case, a label) to
do so. You helped me with that. However, that circumvented the initial
goal. Now, if the tab control was currently focused on the fourth page
(Me.TabControl = 3), then clicking on the object would have to happen
through the four remaining pages, as well as the first page, before
getting to the second page - the initial goal of the object (defeating
the lazy part!). So here I was trying to choose between features - and
hoping I could figure out how to have my cake and eat it too.

I hope that makes a little more sense to you. Does it?

magmike- Hide quoted text -

- Show quoted text -

Actually, I already have the tabs set to none, as I have used my own
labels to act as tabs. I was thinking I would have to go to command
buttons for the flipping feature, but was also hoping I could make the
tabs (the labels) be dual purpose. I do like having the page number
text box in between the buttons as well, so thanks for that idea!

PS - I am going to play with this some more. I thinking I can use a
variable to set a count, and each time the label is clicked, add 1 to
the count. Using If, when the count equals Me.Tabs.Pages.Count -1,
then, clicking would cause Me.Tabs to equal the current, else Me.Tabs
= Me.Tabs + 1 and add one to the count in the variable. Now I just
need to study up on creating variables.

Any corrections needed to my idea?

magmike
 
K

Klatuu

Actually, you don't need a variable at all. Look at this line:

If Me.MyTabControl < Me.MyTabControl.Pages.Count - 1 Then

Note that the reference to the controname returns the page you are on and
the .Pages.Count property returns the number of pages. What you have to be
aware of, though, is that pages collection is zero pages, but the count is
the actual number of pages. Note the -1 in the comparison.

Here is a procedure that will do the moving left and right. Pass it -1 to
move left and +1 to more right.

Private Sub TabMover(TabDirection As Long)
With Me
.MyTabControl = .MyTabControl + TabDirection
.cmdPrevious.Enabled = .MyTabControl <> 0
.cmdNext.Enabled = .MyTabControl < .MyTabControl.Pages.Count - 1
.txtCurTab = .MyTabControl.Pages.Count + 1
End With

In the click event for the buttons:
Left
=TabMover(-1)
Right
=TabMover(1)

Now, you have to do the text box and the same checks.

Private Sub txtCurTab_AfterUpdate()

With Me
.MyTabControl = .txtCurTab - 1
.cmdPrevious.Enabled = .MyTabControl <> 0
.cmdNext.Enabled = .MyTabControl < .MyTabControl.Pages.Count - 1
.txtCurTab = .MyTabControl.Pages.Count + 1
End With

Okay, simple as that.
 
K

Klatuu

Oops, left out a part. To prevent a user entering a number out of range you
need to use the Before Update event.

Private Sub txtCurTab_BeforeUpdate(Cancel As Integer)

With Me
If .txtCurTab < 0 Or .txtCurTab > .MyTabControl -1 Then
Cancel = True
.txtCurTab.Undo
End If
End With


You can set up tab controls so there are no tabs showing, so what you are
after is not entirely unreasonable. Just thinking off the top of my head
and incorporating Larry Hahm's suggestion, you could set up two small
command buttons with a small text box between them - much like the Access
navigation buttons - with left and right arrows.

Then you could display the current page number in the text box and allow
the
user to move forward and back using the command buttons or jump to a
specific page using the text box.















In truth, this is more exercise than reality - I was trying to make
sense of the logic and obviously failed. That said - the initial goal
was to have the click of this particular object (a label) send focus
to the 2nd page in the tab control (Me.TabControl = 1). Then I started
thinking, it would be cool (since I am always finding ways to be more
lazy!), if, instead of having to move the cursor with the mouse to
each tab and click to navigate through the tabs, what if the user
could just keep clicking on the same object (in this case, a label) to
do so. You helped me with that. However, that circumvented the initial
goal. Now, if the tab control was currently focused on the fourth page
(Me.TabControl = 3), then clicking on the object would have to happen
through the four remaining pages, as well as the first page, before
getting to the second page - the initial goal of the object (defeating
the lazy part!). So here I was trying to choose between features - and
hoping I could figure out how to have my cake and eat it too.

I hope that makes a little more sense to you. Does it?

magmike- Hide quoted text -

- Show quoted text -

Actually, I already have the tabs set to none, as I have used my own
labels to act as tabs. I was thinking I would have to go to command
buttons for the flipping feature, but was also hoping I could make the
tabs (the labels) be dual purpose. I do like having the page number
text box in between the buttons as well, so thanks for that idea!

PS - I am going to play with this some more. I thinking I can use a
variable to set a count, and each time the label is clicked, add 1 to
the count. Using If, when the count equals Me.Tabs.Pages.Count -1,
then, clicking would cause Me.Tabs to equal the current, else Me.Tabs
= Me.Tabs + 1 and add one to the count in the variable. Now I just
need to study up on creating variables.

Any corrections needed to my idea?

magmike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top