Radio button/Option group queries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matthais86
    New Member
    • Oct 2013
    • 1

    Radio button/Option group queries

    Hi. I work for a small consumer PC repair company as a workshop technician, but have recently been tossed into the deep end on coding an Access/VBA system for a client despite not having used VB since a school project nearly a decade ago. I am using Access 2013.

    I am currently struggling with disabling and enabling a set of three text boxes (txtYears, txtMonths, txtDays) depending on the status of a radio button option group containing buttons optD & optI, with D enabling the text boxes and I disabling. There is no default value and I would ideally want the textboxes disabled until an option is selected.

    I have a had a look at a couple of similar questions
    (Here & here), but have been so far unable to successfully adapt the solutions provided for those circumstances to my own.

    I also ideally need to make one of the forms combo boxes selection options vary based upon the same pair of radio buttons: the SQL query for the combo box's options needs to be "Where Team = '1'" if optD is selected and "Where Team = '2'" if optI is selected). Is this feasible?

    Any help would be much appreciated.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    An Option Group has a value which reflects which of its Radio Buttons is selected. Each Radio Button has a value and, when selected, that value is reflected by the Option Group. It also has an AfterUpdate event, whose event procedure you will want to utilise to change the 'Enabled' status of your various TextBoxes.

    The default 'Enabled' status of your TextBoxes is set in the design. If they are enabled in the design then they will start out as enabled when you open the form until someone does something to change that.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Adding to what NeoPa has already stated, assuming your Option Group is named fraChoices and the Default Option Values for OptD and OptI remain at 1 and 2 consecutively, the Enabling of these Text Boxes can be controlled as follows:
      Code:
      Private Sub fraChoices_AfterUpdate()
      With Me
        ![txtYears].Enabled = (![fraChoices].Value = 1)
        ![txtMonths].Enabled = (![fraChoices].Value = 1)
        ![txtDays].Enabled = (![fraChoices].Value = 1)
      End With
      End Sub

      Comment

      Working...