PDA

View Full Version : [SOLVED:] Tab Button Control



MINCUS1308
06-13-2014, 12:45 PM
I have a user form with multiple textboxes, comboboxes, and buttons.
I have set the tab order and tab stops to chronologically step through them.
The tab key steps through the boxes, like one should expect, 99% of the time.
1% of the time when the Tab key is pressed instead of moving to the next control I get a " " (tab space) placed after the text or combo box entry.

I cannot seem to replicate this on command and it only seems to happen during a demo.
Do the vba gods just hate me or am I just stupid?

Any help would be greatly appreciated.

Aussiebear
06-13-2014, 01:46 PM
Im guessing that the error occurs after the value has been changed within the text box or combo box right?

MINCUS1308
06-13-2014, 01:55 PM
It's during data entry. As I try to tab out of the controls focus.

mikerickson
06-13-2014, 06:45 PM
Make sure that the .TabKeyBehavior property is set to False for all your controls.

MINCUS1308
06-13-2014, 07:04 PM
All tabkeybehaviors are set to false

MINCUS1308
06-16-2014, 05:23 AM
A possible clue to this problem: I found this morning while playing with the form that I am capable of replicating the error 100% of the time if I depress the ctrl key while tab-ing.
My search over the weekend resulted in one reoccurring answer: basically a compiler error.

In yalls experience do you think I could successfully use and ascII 9 work around? or would something like that just bogg my code down?

Thanks

ashleyuk1984
06-16-2014, 07:41 AM
I don't think I've experienced this myself, but it's an interesting problem.
If you have confidential information in your workbook... Are you able to strip it down, and just post the workbook with barebones / dummy data so we can take a look and see where the error is occurring?
At the moment we can only speculate.

mikerickson
06-16-2014, 12:31 PM
You could create a class module, name it clsTextBox and put this code in it.

Public WithEvents myBox As MSForms.TextBox

Private Sub myBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Shift = 2 Then KeyCode = 0
End Sub

Property Set Box(aBox As Variant)
With aBox
.TabKeyBehavior = False
End With
Set myBox = aBox
End Property
Property Get Box() As Variant
Set Box = myBox
End Property
and then put this code in the userform's code module

Dim myTextBoxes As Collection

Private Sub UserForm_Initialize()
Dim newCls As clsTextBox
Dim oneBox As Variant
Set myTextBoxes = New Collection
For Each oneBox In Me.Controls
If TypeName(oneBox) = "TextBox" Then
Set newCls = New clsTextBox
Set newCls.Box = oneBox
myTextBoxes.Add Item:=newCls
End If
Next oneBox
Set newCls = Nothing
End Sub

Private Sub UserForm_Terminate()
Set myTextBoxes = Nothing
End Sub

OR
you could tell your users not to press the Ctrl key at the wrong time.

MINCUS1308
06-17-2014, 05:50 AM
I don't mind sharing my code, but it will take a bit to strip it down. and pressing the ctrl key isn't the problem. its just that doing so results in the same problem. Ill get back to yall with my code.

MINCUS1308
06-24-2014, 10:59 AM
It turns out there is nothing wrong. its a compiler error. there are work arounds available im just checking for asc 9 press and manually stepping to the next box.

Thanks for the help