PDA

View Full Version : Solved: Setting focus to txtbox from Radio box



seeking_help
06-17-2008, 01:49 PM
Hi all,
I am having trouble when I set focus to a text box that is related to an option box. I am using VBA, here is the situation.
I have an option group with 3 radio buttons. One of the buttons has a text box that gets enabled when the radio button gets focus. I want to set focus to the text box right after that to skip the step of a manual click into the text box before you can type. When I try to set the focus it will indeed move the cursor to the textbox but it will not click the radio button. So i am left with the last selected radio button which is incorrect and will give me bogus info(example- opbButton1 is default(has the green dot) when I click opbButton3 the text box associated with it will then be enabled but opbButton1 still has the green dot).

Sample code for opbButton3_GotFocus
'---------------------------------------------
Private Sub opbAnotherProject_GotFocus()
' enables tbdiffprojnum, clears the combo0 box and disables copy btn
tbDiffProjJobNum.Enabled = True
Form_frmPickFixture.Combo0.Value = ""
Form_frmPickFixture.cmdCopyFrom.Enabled = False
End Sub
'------------------------------------------------

I have tried adding tbDiffProjJobNum.SetFocus or Me.<same code>
but that is what gives me the problem I have with the radio button not being clicked.
There is no _Click() event available only MouseUp,Down, or Move.
What I thought was going to be a simple single line of code is giving me fits.
Anyone have any ideas on why this is happening or a way to fix it?

Thanks for the help!
Josh

Carl A
06-17-2008, 02:53 PM
You can do away with the option group and use option buttons and when you select one of the buttons set the other option buttons values to False. example

Private Sub Option1_Click
Text1.SetFocus
Option2.Value = False
Option3 Value = False
End sub
Then do the same for the other Option Buttons

HTH

seeking_help
06-18-2008, 05:51 AM
Is there a way around removing the option group? I have a few very important Case statements that depend on Frame.Value(the option group). If not then it appears that your solution will work to perfection yet again :thumb . I would just have to change my code. Would there be an easier way to do that then changing Case back to If..ElseIf..Else?

Thanks for the help!

seeking_help
06-18-2008, 06:44 AM
I added a sub for Frame that semi-works. It will set the focus correctly but then I can't click out to one of the other radio buttons(say if a user changes their mind or some other odd reason). Can there be modifications made to this to make it work?
-------------------------------------------
Private Sub Frame_AfterUpdate()
If Frame.Value = 3 Then tbDiffProjJobNum.SetFocus
End Sub
--------------------------------------------

Or does this spark any other ideas that might also work?
Thanks for the help!
Josh

seeking_help
06-18-2008, 07:03 AM
Doh, :doh:stupid me, that sub will work just the way it is supposed to. But I forgot to delete that from another sub I tried it in at first. So that was keeping it from clicking out because it kept setting focus to that no matter what. Memory lapses are not fun. But it is fully functional now.
Thanks for the help!
Josh

Carl A
06-18-2008, 07:12 AM
A less reliable way is to use sendkeys which I really don't recommend. But here it is

Private Sub Option3_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Text1.SetFocus
End If
End Sub

Private Sub Option3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
SendKeys "{ENTER}"
End If
End Sub

seeking_help
06-18-2008, 07:30 AM
A less reliable way is to use sendkeys which I really don't recommend. But here it is

Private Sub Option3_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Text1.SetFocus
End If
End Sub

Private Sub Option3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
SendKeys "{ENTER}"
End If
End Sub




Thanks for that, I was trying to do something of exactly the same sort before I thought of the AfterUpdate. I could not figure it out and get that way to work though. Now I know how it works and what I was doing wrong.
Thanks for the info!
Im sure I will be back for more help soon.
Josh