Next page, Previuous page and First Page cmd buttons

S

sebastico

I have a form with 8 pages tab. I have a code (in each page) to skip to next
page and so on to 7:
Private Sub Command15_Click()
With TabCtl0
If .Value = .Pages.Count - 1 Then
' It's the last page, so go back to the first page.
..Value = 0
Else
..Value = .Value + 1
End If
End With
End Sub

I need 2 more cmd buttons. One to skip to previous page (in each page)and
another one to to go back from last page to first page.

Does any body could help me? Many thanks
 
S

Steve

To skip to previous page ---
You only need one button outside the tabcontrol with the following code in
the click event:
If Me!Tabctl0.Value = 0 Then
Msgbox "On First Page"
Else
Me!Tabctl0.Value = Me!Tabctl0.Value - 1
End If


To go back from last page to first page ---
You only need one button outside the tabcontrol with the following code in
the click event:
If Me!Tabctl0.Value = 0 Then
Msgbox "On First Page"
Else
Me!Tabctl0.Value = 0
End If



PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
 
K

Klatuu

You almost have it.

Private Sub cmdNextPage_Click()
With TabCtl0
If .Value = .Pages.Count - 1 Then
' It's the last page, so go back to the first page.
.Value = 0
Else
.Value = .Value + 1
End If
End With
End Sub

Private Sub cmdPreviousPage_Click()
With TabCtl0
If .Value = 0 Then
' It's the firstst page, so go to the last page.
.Value = .Pages.Count -1
Else
.Value = .Value - 1
End If
End With
End Sub

BTW, notice the indentation. Isn't that much easier to read?
 
S

sebastico

Steve said:
To skip to previous page ---
You only need one button outside the tabcontrol with the following code in
the click event:
If Me!Tabctl0.Value = 0 Then
Msgbox "On First Page"
Else
Me!Tabctl0.Value = Me!Tabctl0.Value - 1
End If


To go back from last page to first page ---
You only need one button outside the tabcontrol with the following code in
the click event:
If Me!Tabctl0.Value = 0 Then
Msgbox "On First Page"
Else
Me!Tabctl0.Value = 0
End If



PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]







Great. Thank you very much
 
S

sebastico

It Works!!!Thank you very much indeed.

Klatuu said:
You almost have it.

Private Sub cmdNextPage_Click()
With TabCtl0
If .Value = .Pages.Count - 1 Then
' It's the last page, so go back to the first page.
.Value = 0
Else
.Value = .Value + 1
End If
End With
End Sub

Private Sub cmdPreviousPage_Click()
With TabCtl0
If .Value = 0 Then
' It's the firstst page, so go to the last page.
.Value = .Pages.Count -1
Else
.Value = .Value - 1
End If
End With
End Sub

BTW, notice the indentation. Isn't that much easier to read?
 
Top