I've 4 option buttons in a Frame. Must one be selected when the Form loads or not?
I've tried setting all .value= False but the top one is still selected.
Thanks
My recollection (what I have noticed) is that there is always one selected.
You could have an additional button and position it out of sight, setting it's Value to true
I've 4 option buttons in a Frame. Must one be selected when the Form loads or not?
I've tried setting all .value= False but the top one is still selected.
Thanks
Set the TabIndex property of some other control to 0.
The option button that gets selected must have TabIndex 0 now, and so it gets the focus and then it gets selected.
The Frame has tab index of 10 and the four buttons are 11-14. I set another button to tab index 0.
But the top button in the frame is checked no matter what. I tried setting focus to a textbox but run time error 5. (that puzzles me, you can't set focus to a text box?)
Also Bobbles, that doesn't remove the check either, the other option becomes checked as well.
> An option group always has one member control "on" even in a group of 1 control.
Ok thanks I'll revise strategy to expect that.
But in Form Load
txtPath= "Some text"
txtPath.SetFocus.
> An option group always has one member control "on" even in a group of 1 control.
Ok thanks I'll revise strategy to expect that.
But in Form Load
txtPath= "Some text"
txtPath.SetFocus.
Why does that raise an error 5 ?
Originally Posted by SamOscarBrown
1-Do what Eduardo says...will 'fix' (answer) your initial question.
2-Put txtpath.SetFocus in Form_Activate, not Form_Load. Will 'fix' your error.
To fully answer that question - it's because loading the form doesn't show the form. You can't set focus to something that isn't shown. In the load event, that's just the first step or several during the creation process. But the form isn't drawn yet, and so controls on it can't have focus set yet. (but you can set text, I know counterinuitive, but that's the way it is.)
Thanks for the gen on setFocus. Nice to have that sorted. And the example files, were really helpful.
At first I could not emulate Eduardos example even after re-ordering the tab indexes so a Text box was 0. The top button in the Frame was True.
Then the penny dropped, the other controls were not enabled, the idea being they would become enabled depending on which option was True.
Bobbles method with option top set to -999 also worked ok now.
This is a similar problem to the ComboBox problem in another thread. When a control has TabIndex=0, it's easy for the user to do something that fouls up that control (such as hit the space bar, or start typing and not realizing where they are). For me, the solution is to always have a TextBox as the TabIndex=0 control, or to have some "off form" (say Left=-999) control that does nothing but has TabIndex=0. This is my "goto" solution for these things. After the form loads and this "off form" control gets the focus, you could even turn off TabStop on this "off form" control so that it's not in the subsequent tab order.
Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.