Tab Control using Next button (1 Viewer)

tsingh

New member
Local time
Today, 00:56
Joined
Feb 9, 2006
Messages
5
I would like to use a Next button instead of having users click the tabs. Can this be done eaisly? Please help

Thanks
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:56
Joined
Jul 9, 2003
Messages
16,285
Example you may be able to hack

There is an example in this thread that allows you to password protect a tab on a tab control. I know it's not what you were looking for, however I think it should give you some clues. Have a go, and if you need some help re-post.
 

tsingh

New member
Local time
Today, 00:56
Joined
Feb 9, 2006
Messages
5
Still needing help.

The only difference I can tell between tabs is the Page Index Value and I don't know how to address that in a button. Please help as I am new to Access programming. Thanks
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:56
Joined
Jul 9, 2003
Messages
16,285
Add this code to the example

The tab control is quite an arkward control to use in MS Access, it is not intuitive.

Add the following code to the example (the dim statement must go right at the beginning) you will also need to add a button called "btnNxtTab" also if you press the button to many times, it will try and set the value of a nonexistent Tab and cause an error. You will have to trap for this error or redesign the code so that the error does not occur.

Code:
Dim intNext As Integer



Private Sub Form_Load()
'Set the initial value of intNext
intNext = 1
End Sub



Private Sub btnNxtTab_Click()
'this button selects the next tab
On Error GoTo Err_btnNxtTab_Click

'this line of code moves the focus to the next tab
   TabCtl0.Pages.Item(intNext).SetFocus
'and this line of code increases the value of intNext by one so that it is ready to select the next tab
   intNext = intNext + 1
   
Exit_btnNxtTab_Click:
    Exit Sub

Err_btnNxtTab_Click:
    MsgBox Err.Description
    Resume Exit_btnNxtTab_Click
    
End Sub
 

tsingh

New member
Local time
Today, 00:56
Joined
Feb 9, 2006
Messages
5
Thanks Uncle Gizmo, with slight modification of your code I was able to get it to work perfectely.

Thanks again.
 

tsingh

New member
Local time
Today, 00:56
Joined
Feb 9, 2006
Messages
5
My solution to adding the next button on a tab ctrl. I am a beginner so it may not be as pretty as it should be, but it works.


Code:

Private Sub btnNxtTab_Click()
'this button selects the next tab
On Error GoTo Err_btnNxtTab_Click

'this line of code moves the focus to the next tab
TabCtl439.Pages.Item(1).SetFocus
'and this line of code increases the value of intNext by one so that it is ready to select the next tab


Exit_btnNxtTab_Click:
Exit Sub

Err_btnNxtTab_Click:
MsgBox Err.Description
Resume Exit_btnNxtTab_Click

End Sub

Private Sub Command465_Click()

On Error GoTo Err_Command465_Click

TabCtl439.Pages.Item(2).SetFocus

Exit_Command465_Click:
Exit Sub

Err_Command465_Click:
MsgBox Err.Description
Resume Exit_Command465_Click

End Sub
Private Sub Command466_Click()
On Error GoTo Err_Command466_Click

TabCtl439.Pages.Item(3).SetFocus


Exit_Command466_Click:
Exit Sub

Err_Command466_Click:
MsgBox Err.Description
Resume Exit_Command466_Click

End Sub
Private Sub Command467_Click()
On Error GoTo Err_Command467_Click

TabCtl439.Pages.Item(4).SetFocus


Exit_Command467_Click:
Exit Sub

Err_Command467_Click:
MsgBox Err.Description
Resume Exit_Command467_Click

End Sub
Private Sub Command468_Click()
On Error GoTo Err_Command468_Click

TabCtl439.Pages.Item(5).SetFocus

Exit_Command468_Click:
Exit Sub

Err_Command468_Click:
MsgBox Err.Description
Resume Exit_Command468_Click

End Sub
 

Banana

split with a cherry atop.
Local time
Yesterday, 21:56
Joined
Sep 1, 2005
Messages
6,318
*bump*

I'm hoping that someone might be able to help a bit on this.

I'm trying to see if I can get tabs to have set their corresponding subforms at new records.

I experimented with the above code, but cannot see how I would be able to get the index to determine which tab is selected, and on top of this, it looks like
Code:
DoCmd.RunCommand acCmdRecordGoToNew[/url] is only available if you call it inside a form subroutine, not outside, even with setfocus set to subforms..

Anyone has a suggestion how I might accomplish of keeping tabs' subform at new records whenever user changes tabs?
 

RuralGuy

AWF VIP
Local time
Yesterday, 22:56
Joined
Jul 2, 2005
Messages
13,826
Use the TabCtl Change event!
Code:
Private Sub TabCtl2_Change()
On Error GoTo Err_TabCtl2_Change

Select Case Me.TabCtl2.value

    Case 0
        '-- You are going into the 1st tab
        '-- Execute your code
    Case 1
        '-- You are going into the 2nd tab
        '-- Execute your code
    Case 2
        '-- You are going into the 3rd tab
        '-- Execute your code    Case Else
    Case Else
        '-- It is none of the above tabs!
End Select

Exit_TabCtl2_Change:
    Exit Sub
    
Err_TabCtl2_Change:
   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume Exit_TabCtl2_Change

End Sub
 

Banana

split with a cherry atop.
Local time
Yesterday, 21:56
Joined
Sep 1, 2005
Messages
6,318
Ahh, now that makes perfect sense. I knew about OnChange event, but didn't know how to catch which tab index it would be at. This is perfect.

Now to tackle the problem of getting the subform to set at a new record.

Thanks, RG!

Edit= For those interested, here is the code that will allow one to move a subform to a new record.

Code:
Me.CreditorsSuppTxnsSUB.Form!AddressesID.SetFocus
    If Not Me.CreditorsSuppTxnsSUB.Form.NewRecord Then
        DoCmd.RunCommand acCmdRecordsGoToNew
    End If

Credits to Allen Browne, at Access group at google.com
 
Last edited:

Users who are viewing this thread

Top Bottom