Changing tab pages programmatically

I

Imran Ghani

Hi! I am using MS Access 2007 with VBA. I am using tab pages to show the
information of my form. I want to be able to move to the next and previous
pages programmatically by making two buttons of next and previous. Whichever
button is clicked, the movement should be shown by the tab pages,
correspondingly. Thanks for help in advance.
 
T

tina

well, the value of the tab control is equal to the value of the page index
of the current page in the tab control. confusing? let's look at an example:

you have a tab control with three pages. the PageIndex is zero-based, so the
first page in the tab order has a PageIndex value of zero (0), the second
page has PageIndex value of 1, and the third page has PageIndex = 2.
so when the second page is "current", the value of the tab control = 1, when
the third page is current, the tab control = 2, and when the first page is
current, tab control = 0.

now that you understand how the tab control works, you can change the
"current" tab page, by changing the value of the tab control. so add the
following code to the "Next" command button, as

On Error Resume Next
Me!TabCtl0 = Me!TabCtl0 + 1

and add the following code to the "Previous" command button, as

On Error Resume Next
Me!TabCtl0 = Me!TabCtl0 - 1

hth
 
T

tina

well, the value of the tab control is equal to the value of the page index
of the current page in the tab control. confusing? let's look at an example:

you have a tab control with three pages. the PageIndex is zero-based, so the
first page in the tab order has a PageIndex value of zero (0), the second
page has PageIndex value of 1, and the third page has PageIndex = 2.
so when the second page is "current", the value of the tab control = 1, when
the third page is current, the tab control = 2, and when the first page is
current, tab control = 0.

now that you understand how the tab control works, you can change the
"current" tab page, by changing the value of the tab control. so add the
following code to the "Next" command button, as

On Error Resume Next
Me!TabCtl0 = Me!TabCtl0 + 1

and add the following code to the "Previous" command button, as

On Error Resume Next
Me!TabCtl0 = Me!TabCtl0 - 1

hth
 
I

Imran Ghani

Thank you for your helpful notes. Further to this I want to first get the
value of the tab page user is currently in and then increment or decrement
according to the value of this page which I can get through maybe some
variable. Kindly guide me for the same purpose.
 
I

Imran Ghani

Thank you for your helpful notes. Further to this I want to first get the
value of the tab page user is currently in and then increment or decrement
according to the value of this page which I can get through maybe some
variable. Kindly guide me for the same purpose.
 
T

tina

a tab page doesn't have a "value" per se, it's not a control in itself but
rather an element of a control. the closest you're going to get is the
PageIndex property, but presumably that should suffice since it's a unique
value for each page - in other words, you'll never have two pages with the
same PageIndex number, in a single tab control.

hth
 
T

tina

a tab page doesn't have a "value" per se, it's not a control in itself but
rather an element of a control. the closest you're going to get is the
PageIndex property, but presumably that should suffice since it's a unique
value for each page - in other words, you'll never have two pages with the
same PageIndex number, in a single tab control.

hth
 
I

Imran Ghani

Thanks for your valuable help. Kindly also guide me about how to have my
command buttons on the tab page. I want to have a same set of command buttons
for all the form, I mean all the tab pages included in the form.
 
I

Imran Ghani

Thanks for your valuable help. Kindly also guide me about how to have my
command buttons on the tab page. I want to have a same set of command buttons
for all the form, I mean all the tab pages included in the form.
 
I

Imran Ghani

Thanks for your kind help. I want to use the next and previous buttons to be
able to be applied on the tab pages. Can it be done for all the tab page or
should we have different buttons for different pages.
 
I

Imran Ghani

Thanks for your kind help. I want to use the next and previous buttons to be
able to be applied on the tab pages. Can it be done for all the tab page or
should we have different buttons for different pages.
 
T

tina

just use two buttons, one for Previous, and one for Next. *don't* put them
ON the tab control. instead, put them in the same section of the form that
the tab control is in (probably the Detail section, i'm guessing), and then
move them "behind" the tab control. the command buttons will then show
through on every page.

hth
 
T

tina

just use two buttons, one for Previous, and one for Next. *don't* put them
ON the tab control. instead, put them in the same section of the form that
the tab control is in (probably the Detail section, i'm guessing), and then
move them "behind" the tab control. the command buttons will then show
through on every page.

hth
 
I

Imran Ghani

Thanks again for your kind advise. Please also guide me about how to code
those two buttons so that they may be used with all the tab pages. I am sorry
I am a novice and hence not able to understand about how to move those
butttons behind the tab control.
 
I

Imran Ghani

Thanks again for your kind advise. Please also guide me about how to code
those two buttons so that they may be used with all the tab pages. I am sorry
I am a novice and hence not able to understand about how to move those
butttons behind the tab control.
 
R

Rick Brandt

Thanks again for your kind advise. Please also guide me about how to
code those two buttons so that they may be used with all the tab pages.
I am sorry I am a novice and hence not able to understand about how to
move those butttons behind the tab control.

Create them outside the boundaries of the TabControl then drag them where
you want them. You cannot drag an existing control onto a TabPage so
this automatically puts them behind your TabControl (or in front
depending on your perspective).

It is way more common in these groups to get questions because people
ended up with objects behind the TabControl when that is not what they
wanted.

Since the code affects the value of the entire TabControl and does not
even reference the pages the code automatically works for all pages.
 
R

Rick Brandt

Thanks again for your kind advise. Please also guide me about how to
code those two buttons so that they may be used with all the tab pages.
I am sorry I am a novice and hence not able to understand about how to
move those butttons behind the tab control.

Create them outside the boundaries of the TabControl then drag them where
you want them. You cannot drag an existing control onto a TabPage so
this automatically puts them behind your TabControl (or in front
depending on your perspective).

It is way more common in these groups to get questions because people
ended up with objects behind the TabControl when that is not what they
wanted.

Since the code affects the value of the entire TabControl and does not
even reference the pages the code automatically works for all pages.
 
T

tina

thanks for picking up the slack, Rick. :)
btw, i say "behind" the tab control, because if you move an on-tabpage
control into the same spot where an off-tabpage control is, the on-tabpage
control will cover up the off-tabpage control.
 
T

tina

thanks for picking up the slack, Rick. :)
btw, i say "behind" the tab control, because if you move an on-tabpage
control into the same spot where an off-tabpage control is, the on-tabpage
control will cover up the off-tabpage control.
 
I

Imran Ghani

Thanks for your helping advise, I was able to make two buttons who are
working fine with all the tab pages. Please also advise me, if there is any
way, we can have more than one set of tab pages on the same form. When I
click one tab page, whole of the set should come in front, and the other sets
go back, this way I may be able to put more information in less space. Is it
possible with MS Access 2007?

tina said:
thanks for picking up the slack, Rick. :)
btw, i say "behind" the tab control, because if you move an on-tabpage
control into the same spot where an off-tabpage control is, the on-tabpage
control will cover up the off-tabpage control.
 

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