TabControl and Ctrl-Tab

M

Mitch Powell

I am using a tab control with style set to None (no tabs) and control the
page display through VBA. Problem is that a Ctr-Tab ketroke combination
still cyclces through the pages as if the tabs were visible with the focus.
This lets the user inadvertantly change pages.

How do I prevent this from happening?
 
D

Dirk Goldgar

Mitch Powell said:
I am using a tab control with style set to None (no tabs) and control the
page display through VBA. Problem is that a Ctr-Tab ketroke combination
still cyclces through the pages as if the tabs were visible with the
focus.
This lets the user inadvertantly change pages.

How do I prevent this from happening?


I can think of a couple of ways:

1) Trap and ignore the keystroke
---------------------------------------------

To do this, set the form's KeyPreview property to Yes, and then use code
like this in the form's KeyDown event:

'----- start of code -----
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyTab _
And (Shift And acCtrlMask) > 0 _
Then
KeyCode = 0 ' swallow the key
End If

End Sub
'----- end of code -----


2) Use code to prevent the tab from changing
--------------------------------------------------------------

Have a module-level variable to hold the PageIndex of the tab page you want
to keep current. Then in the tab cotrol's Change event, have code that
forces it back to that page:

'----- start of (relevant) code from form's module -----
Option Compare Database
Option Explicit

Dim mintCurrPage As Integer

Private Sub tabMyTab_Change()

If Me.tabMyTab <> mintCurrPage Then
Me.tabMyTab = mintCurrPage
End If

End Sub

Private Sub ChangeTabPage(intPage As Integer)

mintCurrPage = intPage

tabMyTab = mintCurrPage

End Sub
'----- end of code -----

As you see above, you would have your own routine to change the tab page,
which would include changing the module level variable.

3) Make inactive pages invisible
 

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