Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2012
    Posts
    31

    Unanswered: 'Radio buttons' to enable text box selection (ms access)

    Hi folks,

    I want to have two 'radio buttons' on my form. One button will be labelled YES and the other NO.

    I want to link these radio buttons to TWO text boxes.

    By default, NO should be selected and users can not enter data into either text box.

    If however, they click the radio button labelled YES, the text box activates and allows text entry into BOTH text boxes.

    Could any body give me some guidance to the code i would need to use?

    Thanks in advance

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    It’s sort of complicated, so here’s a step-by-step. If I say 'name it'’ do so, but replace Textbox1 and Textbox2 with the actual names of your Textboxes.

    1. Add a Numbers Field to your underlying Table; name it OptionField
    2. Place an Option Group on your Form
    3. Enter your LabelsYes for the first one…No for the second one
    4. Hit Next
    5. Set 'Yes, the Default Is' to No
    6. Hit Next
    7. Note that Yes will generate a Value of 1No will generate a Value of 2
    8. Hit Next
    9. Select 'Save the Value in this Field and enter OptionField
    10. Hit Next
    11. Select Option Button (this is the actual name for ‘radio buttons’ in Access)
    12. Hit Next
    13. Enter a Label for your Option Group
    14. Hit Finish

    Your Option Group Control will now be selected.

    • Go to Properties – Other and enter OptionSelection in the Name Property
    • Click on the Events Tab
    • Click on the ellipsis () and select Code Module, if need be
    • You’re now in the Code Module and should see

    Code:
    Private Sub OptionSelection_Click()
    
    End Sub

    Now modify this to show

    Code:
    Private Sub OptionSelection_Click()
     
     If Me.OptionSelection = 2 Then
      
      Textbox1.Visible = False
      Textbox2.Visible = False
      
      Me.Textbox1 = Null
      Me.Textbox2 = Null
      
     Else
      
      Textbox1.Visible = True
      Textbox2.Visible = True
     
     End If
    
    End Sub

    Now create another Sub, entering this

    Code:
    Private Sub Form_Current()
      
      If Me.OptionSelection = 2 Then
      
      Textbox1.Visible = False
      Textbox2.Visible = False
      
     Else
      
      Textbox1.Visible = True
      Textbox2.Visible = True
     
     End If
    
    End Sub

    Note that the lines of code

    Me.Textbox1 = Null
    Me.Textbox2 = Null


    are included in case the user clicks on 'Yes,' enters data in the Textboxes, then realizes that he has made a mistake. When the user now clicks on 'No,' the data that was erroneously entered is deleted.

    You should now be set!

    Linq ;0)>
    Last edited by Missinglinq; 03-14-15 at 12:48.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

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