Results 1 to 14 of 14

Thread: Newbie type option button question/problem.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8

    Post Newbie type option button question/problem.

    I have a form with 3 option buttons on it, optYes, optNo and optMaybe. Selection of any option button pops up a corresponding message box. Now the problem is this. Whenever the form loads, the code for optYes fires. I have set the value of all three option buttons to False in the Form load, but still the same problem happens. I have even tried making and invisible option button, setting its value to True....same problem. Any ideas?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    When you set the Value property of an option button, it fires the Click event. Try setting their values in the IDE.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8
    Grrrrr, same problem. I've set the values for the 3 option boxes to false both in the IDE and when the form loads. For some reason, the Yes option box click event fires off as soon as the form loads.

  4. #4
    WorkHorse
    Guest
    Yeah, strange. The value of the first option button not set to False in the code is set to True when the form loads no matter what the value is set as in the IDE. If the code sets all opts to False it still fires a click event on the first opt (considering it being changed from True to False). I guess you would either need to put the buttons in a container (like a borderless frame) or set a flag when the form loads to skip the code in the opt click event. Seems like there is something we are missing...

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8
    Ok, I tried the frame idea and got the same results :{ As for the other idea with the flag, I'm too much of a clueless n00b to know how to do it!

    There has got to be some kind of easy answer to this one...it cant be this difficult!

  6. #6
    WorkHorse
    Guest
    I can't think. Anyway, here's the dirty flag method:

    VB Code:
    1. Dim flag As Boolean
    2.  
    3. Private Sub Form_Load()
    4.     flag = True
    5. End Sub
    6.  
    7. Private Sub Option1_Click()
    8.     If flag = False Then
    9.         MsgBox Option1.Value
    10.     Else
    11.         Option1.Value = False
    12.         flag = False
    13.     End If
    14. End Sub

  7. #7
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    The value is only set 'automatically' if it is the first item in the form's taborder. Can u make another control be the first one? If not, use flags.
    Regards
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8
    I placed an invisible option button on the form, set its value to true (I tried false as well), set its taborder to 0.....same problem :{ Guess I'll have to go with the flag idea. Thanks for all the help guys.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    What is the TabIndex of the option button that fires? If it is 0, then there is your problem.

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8
    Originally posted by Hack
    What is the TabIndex of the option button that fires? If it is 0, then there is your problem.
    Originally it was set to 1. I added the invisible option button and set that item's tabindex to 0...same problem.

  11. #11
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    If the new option button is invisible it defeats the purpose becos u cant set focus to an invisible control. If you have no other visible controls that you could make taborder = 0 then u will just have to use a flag method
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Los Angeles
    Posts
    8
    Originally posted by beachbum
    If the new option button is invisible it defeats the purpose becos u cant set focus to an invisible control. If you have no other visible controls that you could make taborder = 0 then u will just have to use a flag method
    Ah! I didnt know that you couldnt set focus to an invisible control. Now that you mention it though, it makes perfect sense. Looks like the flag method is it. Thanks again guys :}

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Have you tried putting a break on the Form_Load and using F8 to walk through the code to see at what point the option button code is being fired?

  14. #14
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    what about if you set their Enabled property to False, then set the values, then set their Enabled propert to True afterwards?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width