I know this is pretty basic, but I'm having trouble with the VBA coding in my form. I have a field with a combo box. If "other" is checked, I would like a new test box field to appear below it to describe the "other" category. If "Other" is not checked, then I want the text box field hidden in my form. Thanks for any help.
Thank you for your help. Does it matter if the combo box is a check box, i.e. "Other" should be checked in order to make the following text box become visible.
Here are a few other considerations ...
First, I don't recommend showing and hiding controls in response to user input or the state of the data, but rather enable or disable them. This preserves the design of your form, and educates the user about all his options even if some of those options aren't currently available.
Second, when dealing with boolean values you don't need this constuct ...
Code:
if condition1 = true then
condition2 = true
else
condition2 = false
end if
Note that you can express this same logic more succinctly as follows...
Code:
condition2 = condition1
Third, if you have a control that should only be enabled when 'chkOther' is true, then you'll need to perform this check and potentially change the enabled state of the control for every record in the form. In this case you'll need to the use the Form_Current() event. And as Kryst observes this'll need to be done also in the AfterUpdate event of the checkbox, so you might need code like ...
Code:
private sub form_current()
resetform
end sub
private sub chkOther_click()
resetform
end sub
private sub resetform()
me.somecontrol.enabled = me.chkOther
end sub
Here are a few other considerations ...
First, I don't recommend showing and hiding controls in response to user input or the state of the data, but rather enable or disable them. This preserves the design of your form, and educates the user about all his options even if some of those options aren't currently available.
Second, when dealing with boolean values you don't need this constuct ...
Code:
if condition1 = true then
condition2 = true
else
condition2 = false
end if
Note that you can express this same logic more succinctly as follows...
Code:
condition2 = condition1
Third, if you have a control that should only be enabled when 'chkOther' is true, then you'll need to perform this check and potentially change the enabled state of the control for every record in the form. In this case you'll need to the use the Form_Current() event. And as Kryst observes this'll need to be done also in the AfterUpdate event of the checkbox, so you might need code like ...
Code:
private sub form_current()
resetform
end sub
private sub chkOther_click()
resetform
end sub
private sub resetform()
me.somecontrol.enabled = me.chkOther
end sub
Thanks. A few more beginner questions: Is Form_Current the same as OnClick in 2007?
Also, when you all use me.before the field name, what is that referring too?
The Current() and Click() events are not even remotely the same. The current event is raised by the form whenever it loads a different record including a new record and including when the form is first opened. The current event is commonly used to update user interface elements that depend on the data in the current record. This is the case for you if you store the value of chkOther in the table, and you need controls to be enabled, or not, when a record containing chkOther is first displayed.
And 'Me' returns a reference to the object in which code is currently running.
Thanks. A few more beginner questions: Is Form_Current the same as OnClick in 2007?
Also, when you all use me.before the field name, what is that referring too?