473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

hide text boxes in a form unless specific item is checked in a combo box?

I have a pretty simple database I started but am stuck at one particular point. In the database I have 1 table and 1 form. My users type data in the form only. I have a combo box in the form with the following items to choose from: AR, Increase, Transfer, ARR, ARI, and BOBC. What I would like to do is have certain fields (or text boxes) only be visible or able to type in, if the 3rd item (Transfer) in the combo box is checked. Is there an easy way to do this? I've done some searching and what I've found is related to the AfterUpdate function in properties. I'm just not tech savvy enough to know what to type in. I can provide screen shots or more specific data if needed. I've seen other posts that have some pretty involved info to enter in order to get the results I think I'm looking for, but many are worded in such a way that I'm having difficulty following, such as: Me!name.visible=false Private Sub check3_after update. I just haven't been able to follow that logic yet!
Thanks for any and all help!
Jun 18 '12 #1
2 11164
beacon
579 512MB
Hi,

Welcome to Bytes!

What you're trying to do is simple enough, but it can be somewhat daunting if you've never done anything like it before.

The first thing you need to do, with your form in Design View, is click on the combo box and navigate the properties (right-click and choose Properties if your properties aren't immediately available) for the AfterUpdate event. Click the dropdown, choose Event Procedure, then click the box next to the dropdown with the elipsis (...).

You will then be taken to the VBA editor and a bit of code will be auto-generated for you that looks like this (where cboYourComboBox is my assumed name for your combo box...clever, I know):

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboYourComboBox_AfterUpdate()
  2.  
  3. End Sub
  4.  
In this code block, you will type your code to complete the action you're after. I'm going to assume you have a text box called txtFirstTextBox in order to show you a code example.

With this control (you called them fields, but control is the appropriate term) you will identify the properties, such as visibility or type-ability (I'm not sure that's a word) in the code block like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboYourComboBox_AfterUpdate()
  2.  
  3.      If cboYourComboBox = "Transfer" Then
  4.           txtFirstTextBox.Visible = True     'Set text box to visible
  5.           txtFirstTextBox.Enabled = True     'Enable the text box
  6.           txtFirstTextBox.Locked = False     'Unlock the text box
  7.      Else
  8.           txtFirstTextBox.Visible = False     'Hide the text box
  9.           txtFirstTextBox.Enabled = False     'Disable the text box
  10.           txtFirstTextBox.Locked = True     'Lock the text box
  11.      End If
  12.  
  13. End Sub
  14.  
The code above will do everything you need it to do, although you don't need all the code to accomplish what I'm sure you're after...you'll likely use some combination of the properties.

For instance, a hidden text box doesn't really need to have an enabled/locked property set since you can't type into a hidden text box. However, if you want to make a text box visible, but not allow a user to type in the box, then you could use either the enabled property or the locked property depending on your end game.

If you want the text box visible, but the user can't put the cursor in the textbox, you would set .Enabled to false and not worry about using .Locked. If you want the user to be able to put the cursor in the text box, but not type, then you'd set the .Locked property to false and not worry about the .Enabled property.

There are different combinations you can use, so play around with it until you find something you like.

As you work with this more, you may find that you want to set one text box to visible and hide another text box that was made visible by a different choice in the combo box. Here's a sample of that too, using a second assumed text box called txtSecondTextBox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboYourComboBox_AfterUpdate()
  2.  
  3.      If cboYourComboBox = "Transfer" Then
  4.           txtFirstTextBox.Visible = True     'Set first text box to visible
  5.           txtFirstTextBox.Enabled = True     'Enable the text box
  6.           txtSecondTextBox.Visible = False    'Hide the second text box
  7.           txtSecondTextBox.Enabled = False    'Disable the second text box
  8.      ElseIf cboYourComboBox = "BOBC" Then
  9.           txtFirstTextBox.Visible = False     'Hide the first text box
  10.           txtFirstTextBox.Enabled = False     'Disable the first text box
  11.           txtSecondTextBox.Visible = True     'Set the second text box visible
  12.           txtSecondTextBox.Enabled = True     'Enabled the second text box
  13.      Else     'Hide and disable both text boxes
  14.           txtFirstTextBox.Visible = False
  15.           txtFirstTextBox.Enabled = False
  16.           txtSecondTextBox.Visible = False
  17.           txtSecondTextBox.Enabled = False
  18.      End If
  19.  
  20. End Sub
  21.  
There are more elegant ways to write the above code, but hopefully this is simple enough to get you started.

Hope it helps,
beacon
Jun 18 '12 #2
Thanks Beacon,
I'm still a bit lost. I can't seem to get my reply posted to you either, so I hope this isn't a duplicate reply I'm sending. I tried attaching two screen shots, to show the form I have, and the code I've typed in the VBA editor. But it requires the attachements to be a web link? I'm not sure how to do that. Is there a way I can get the two screen shots on the post, or to you?
Thanks, I appreciate the help so far!
Jun 19 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
4
by: godber | last post by:
I need to populate text boxes for instance with employee information using their unique employee works number selected from a combo box. Can anyone help, I am told thru visual basic this can be...
7
by: Mark | last post by:
Hi All, I have a report which is based on a query which is used to produce QC check sheets. I have quite a few text boxes which are used to display questions depending on the value of one...
4
by: Miguel | last post by:
I have synchronized combo boxes linking Account Type with Customer Names based on the template that Microsoft has in one of its samples databases. There are the appropriate relationships between...
2
by: jw01 | last post by:
I have a form in which there is one combo box and three text boxes: Combo Box: -> Item A -> Item B -> Item C TextBox1: TextBox2: ...
3
by: spranto | last post by:
Hi to you all once again, I'm dealing with user point of view difficulties. I have a 3x3 "matrix" made with text boxes. Some cases require only 2x2. My problem is: How do I hide, or lock...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
2
by: muddasirmunir | last post by:
i am using this code in load event of the form to add item to combo box combobox1.additem "aaa" combobox1.additem "bbb" now i want when i click a buttton all the items in the combo...
15
by: jerrydigital | last post by:
Hello, I am trying to have a section of my form that allows users to "click here" to add additional account numbers. If they "click here", then an additional text box will appear. But, if they...
1
by: stewdizzle | last post by:
I have a from with three radio buttons (same group) and three text boxes. The radio buttons give the user a choice of uploading one, two, or three images. Currently, I have the text boxes load as...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.