Option buttons not selecting properly

stephenlecompte
07-20-2003, 08:12 AM
I have three option buttons and one text Box
The name of the 1st one is: Own.
The name of the 2nd one is: United.
The name of the 3rd one is: Mayflower
The name of the text box is: txtBox(5)

On the form they are side by side except for text box which is on the next line.

O Own O United O Mayflower
_____________
|____________| txtBox(5)

My problem is that when I press my ENTER key it acts like a TAB button highlighting the next field. When I press the TAB key it acts like an ENTER button going to the next line. Also, when I choose the ENTER key it not only moves to the next option button - but it changes the value of the previous option it was highlighted and selects the option button that it is currently on. I want these set of commands do the opposite - if the User presses TAB then the option switches over to the next field and selects that one to be highlighted. If the User presses ENTER then the choice is finished and go to the next line which happens to be a text box.
I'm sure it has to do with the KeyUp function...but I'm not sure on the exact format.

P.S. I do understand that the last code under Private Sub Mayf_KeyDown(.....) should say If KeyCode = 9 Then txtBox(5).SetFocus but I changed it to the other because I couldn't figure out why the TAB and ENTER key wasn't working properly.


The following is the code:

Private Sub Own_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Or KeyCode = 32 Then Call Text_Box
If KeyCode = 13 Then United.SetFocus
End Sub
Private Sub United_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Or KeyCode = 32 Then Call Text_Box
If KeyCode = 13 Then Mayf.SetFocus
End Sub
Private Sub Mayf_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Or KeyCode = 32 Then Call Text_Box
If KeyCode = 13 Or KeyCode = 9 Then Own.SetFocus
End Sub

passel
07-21-2003, 01:10 AM
Actually, the tab and Enter keys are working properly. The tab key
moves between controls in a container base on Tab Index values. If you
don't want to tab to the text box, then set TabStop to False in the
text box properties. As far as the Enter key going high lighting the next
field, I couldn't get any movement between my option boxes or the
text box when I hit the Enter key, so I don't have a clue there.

The code you have posted doesn't seem to match what you say you want.

Do you want the tab to just cycle through the options boxes and never
go to the text box?

Here's a shot, you can modify it as you see fit.
Turn of the TABSTOP for the text box first.

Private Sub Own_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then 'if tab key pressed
If Shift = 1 Then ' if the shift key is down
Mayf.SetFocus ' cycle backwards
Else ' else
United.SetFocus ' cycle forwards
End If
ElseIf KeyCode = 13 or KeyCode = 32 Then 'elseif the Enter key was pressed then
Text_Box.SetFocus ' move to the text box
End If
End Sub

Private Sub United_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
If Shift = 1 Then
Own.SetFocus
Else
Mayf.SetFocus
End If
ElseIf KeyCode = 13 or KeyCode = 32 Then
Text_Box.SetFocus
End If
End Sub

Private Sub Mayf_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
If Shift = 1 Then
United.SetFocus
Else
Own.SetFocus
End If
ElseIf KeyCode = 13 or KeyCode = 32 Then
Text_Box.SetFocus
End If
End Sub


'If you used a control array for your option buttons then you
'would only need one set of code, similar to this.

Private Sub Option1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then ' tab key
If Shift = 1 Then 'Move Backwards
If Index > 1 Then
Option1(Index-1).SetFocus
End If
EsleIf Index < 2 Then
Option1(Index + 1).SetFocus
End if
ElseIf KeyCode = 13 or KeyCode = 32 Then
Text1.SetFocus
End If
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum