How to link text boxes on a subform to a tick box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • S Crooks
    New Member
    • Nov 2010
    • 1

    #1

    How to link text boxes on a subform to a tick box

    I have created a database form that has subforms, on one of these subforms I want to be able tick the tick box so that it makes the text boxes appear so that information can be inputted. In the propert sheet I changed visibility to No to hide these boxes but do know how to make them reappear on the form when the tick box is ticked. Can anyone help?
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Assuming your check box and the controls you want to unhide are in your subform then you can put the following code in your AfterUpdate event of the check box:

    Code:
        If Me.chkYourCheckBox.Value = True Then
            Me.txtYourControlName.Visible = True
        Else
            Me.txtYourControlName.Visible = False
        End If
    Don't forget to change the control names to what you have.

    cheers,

    Comment

    • Moah Scout
      New Member
      • Oct 2010
      • 58

      #3
      Yeap! Welcome to bytes!!!!
      Suppose you have the txtbox named [Fname] and optionButton named option7.
      According to what I have understand, u want the OptionButton to decide on the visibility of the Fname txtbox depending on the Option7
      If that is the case then do the following:
      1. On the ONLOAD-Event property of a FORM, Use SETVALUE MACRO to set the property of [FName].[Visible]=No and Option7=0
      2. On the AfterUpdate Event of a Option7 set to SETVALUE macro as If FName.Visible=Y es then turn it to No else turn it to Yes.
      See the Attached DB below for more Clarifications
      Attached Files

      Comment

      • Moah Scout
        New Member
        • Oct 2010
        • 58

        #4
        Or you may use this Code to set with VBA at the AfterUpdate Event of Option7
        Code:
        Private Sub Option7_AfterUpdate()
        If Me.FName.Visible = False Then
                FName.Visible = True
                Else: FName.Visible = False
        End If
        End Sub

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          Some points here:

          1) The AfterUpdate Event occurs when the control loses FOCUS, so it does not occur when the 'Tick' box is 'Ticked', but when another control is selected, or the Enter or Tab key is pressed. So ticking the box will not cause the textbox to appear. It will take 2 steps. Better to use the OnClick event.

          Code:
          Private Sub chkYourCheckBox_Click
          	Me.txtYourControlName.Visible = Me.chkYourCheckBox
          	Me.txtYourControlName2.Visible = Me.chkYourCheckBox
          	Me.txtYourControlName2.Visible = Me.chkYourCheckBox
          End Sub
          2) I would set the Enabled Property to True/False instead of the visible property. This would allow the operator to see what they were making available for use. When controls are not visible, a new operator may not find them. Visible but disabled shows them 'greyed-out' so the operator knows they exist: now only must figure out how to enable them.

          3) If the subform View = Continuous Forms,
          a) this will have to be done with Conditional Formatting. For Access 2003, the Enabled Property is available, but the Visible Property is not.
          b) the tickbox will have to be bound to a table entry. An unbound control on a continuous form will change ALL the tickboxes when any one is ticked, and so Lock/Unlock or Show/Hide ALL the textboxes, not just the current record.

          4) If the subform View = Single Form,
          a) the tickbox my have to be set to False if not bound, and
          b) the hidden/locked controls will retain the state of the previous record unless set in the OnCurrent Event.

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            I assumed this was on a continuous form since it does not work in a datasheet view.

            The afterupdate event will fire in a continuous form and works as indicated. You may use the onclick event if you wish also.

            The visible property is available as indicated in A2007.

            As to using enabled or visible I will let the OP decide on that - but it is a valid point since it may not be a good idea to hide the controls from users but rather just disable them. If so just cahnge the visible property to enabled instead in the code.

            The afterupdate will trigger as indicated but would not trigger if changes are made by code. Since we are not making changes to the control via code the afterupdate event will trigger by end user interaction.

            cheers,

            Comment

            Working...