I have several fields, item1, item2, item3, etc...
I want to have a field that is number_of_items, if they select "3" then item1, item2, and item3 become visible on the form so the user can fill them in. How do you do this? Thanks.
You do this by running code to set the .visible property of each text box to "No" on the AfterUpdate property of the number box.
Give us the name of the form(s) and controls, and we'll get some code back to you. Generally though, something like this:
If Me.txtNumber = "1" Then
Me.txtItem1.Visible = "Yes"
ElseIf Me.txtNumber = "2" Then
Me.txtItem1.Visible = "Yes"
Me.txtItem2.visible = "Yes
ElseIf me.txtNumber = "3" Then
...
End If
If you don't have a hundred items to show, then this will work fine. If you have a ton of items to show, the we can do other things.
Let me know.
-Patrick
Nine times out of ten, the simplest solution is the best one.
General syntax for altering a controls visible property (controls are "things" on forms):
[tt]Me!txtItem1.Visible = True[/tt]
- which is one control
You might use if - then - else (if) constructs, select case to match your requirements, toggling each individual control (remember both visible = true AND false for each control), but also I think you could tweak it by using the controls collection, perhaps something like this:
[tt]dim ctl as control
for each ctl in me.controls
if ctl.controltype = actextbox then
if mid$(ctl.name, 1, 7) = "txtItem" then
if mid$(ctl.name, 8) <= me!txtNumber.Value then
ctl.visible = true
else
ctl.visible = false
end if
end if
end if
next ctl[/tt]
- note - typed not tested
This could be called from the txtNumber's after update event, and perhaps also the on current event of the form.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.