Consulting

Results 1 to 2 of 2

Thread: Show\Hide Text Box

  1. #1
    VBAX Newbie
    Joined
    Aug 2013
    Posts
    1
    Location

    Show\Hide Text Box

    I have a Form, on this form is a drop down box ("box1") which for argument sake has three options ("Opt1","Opt2" & "Opt3")
    I Also Have a Text Box ("txt1") Which Is Not Visable

    What I am looking for is some code that makes "txt1" visable when "Opt3" is chosen in the drop down box
    And Hided it again if "Opt1 or Opt2" is selected afterwards

    I feel this should be relativly simple but am struggling to get it to work

    Thankyou in Advance

  2. #2
    Quote Originally Posted by TravD16v View Post
    I have a Form, on this form is a drop down box ("box1") which for argument sake has three options ("Opt1","Opt2" & "Opt3")
    I Also Have a Text Box ("txt1") Which Is Not Visable

    What I am looking for is some code that makes "txt1" visible when "Opt3" is chosen in the drop down box
    And Hided it again if "Opt1 or Opt2" is selected afterwards

    I feel this should be relativly simple but am struggling to get it to work

    Thankyou in Advance
    In the After update event of the combo box try this:


    If Me.Box1.Column(0) = "Opt3" Then
        Me.txt1.Visible = True
    Else
        Me.txt1.Visible = False
    End If
    NOTE: In the above you will need to modify Me.Box1.Column(0) so the column index number is the column in the drop down with the text you want to match. The index starts at Zero. This means if the text Opt3" is in the second column then you would use Me.Box1.Column(1).


    The above code can be simplified to this:
     
    Me.txt1.Visible = ( Me.Box1.Column(0) = "Opt3")
    NOTE: When viewing existing records, the above code from the after update event will need to be executed in the Form's On Current event.



    TIP: It really helps if you will give examples of your actual database design. Then we can give you the best advice on ho to handle it with your database design.

    If this were my project, then drop down combo box would be based on a look up table. The look up table would also include a field for Txt1_required as a yes/no data type. This would be added as hidden column in the drop down list.

    The code can be written like this:
    Me.txt1.Visible =  Val(Me.Box1.Column(2))
    By using this method, it is table driven. This will allow you to easily modify the drop down list without having to edit the VBA code.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

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