Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field Becomes Visible Depending on Input in another field

Status
Not open for further replies.

BadDog

MIS
Aug 19, 1999
166
US
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.
 
BadDog,

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.
 
Can I do something like

If Me.txtNumber >= 1 Then
Me.txtItem1.Visible = "Yes"

So that 1 and 2 will both show if "2" is selected?
 
Nope!

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.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top