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):
-
Private Sub cboYourComboBox_AfterUpdate()
-
-
End Sub
-
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:
-
Private Sub cboYourComboBox_AfterUpdate()
-
-
If cboYourComboBox = "Transfer" Then
-
txtFirstTextBox.Visible = True 'Set text box to visible
-
txtFirstTextBox.Enabled = True 'Enable the text box
-
txtFirstTextBox.Locked = False 'Unlock the text box
-
Else
-
txtFirstTextBox.Visible = False 'Hide the text box
-
txtFirstTextBox.Enabled = False 'Disable the text box
-
txtFirstTextBox.Locked = True 'Lock the text box
-
End If
-
-
End Sub
-
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:
-
Private Sub cboYourComboBox_AfterUpdate()
-
-
If cboYourComboBox = "Transfer" Then
-
txtFirstTextBox.Visible = True 'Set first text box to visible
-
txtFirstTextBox.Enabled = True 'Enable the text box
-
txtSecondTextBox.Visible = False 'Hide the second text box
-
txtSecondTextBox.Enabled = False 'Disable the second text box
-
ElseIf cboYourComboBox = "BOBC" Then
-
txtFirstTextBox.Visible = False 'Hide the first text box
-
txtFirstTextBox.Enabled = False 'Disable the first text box
-
txtSecondTextBox.Visible = True 'Set the second text box visible
-
txtSecondTextBox.Enabled = True 'Enabled the second text box
-
Else 'Hide and disable both text boxes
-
txtFirstTextBox.Visible = False
-
txtFirstTextBox.Enabled = False
-
txtSecondTextBox.Visible = False
-
txtSecondTextBox.Enabled = False
-
End If
-
-
End Sub
-
There are more elegant ways to write the above code, but hopefully this is simple enough to get you started.
Hope it helps,
beacon