Changing mulitple fields visibility from a single data entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to use one control to determine which others within my form are visible
i.e. In a text box labelled 'How Many' if 1 is entered then the text box
labelled 'one' is visible and box's labelled two, three and four are
invisible, if 2 is entered then 'one' and two' are visible and so on.

Any help would be appreciated.

Thanks
 
You've described a "how" ... how you are trying to do something. If you'll
describe the "why" and "what" (what will having this allow you to
accomplish?), the newsgroup readers may be able to offer more specific
suggestions.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
I've taken the liberty of changing your textbox name from How Many to HowMany
to take out the [space]. You really shouldn't have spaces in object names!

This is assuming that the data in HowMany is numeric. If it is text instead,
you need to change the Case statements from

Case 1

to

Case "1"

and so forth.

'Code begins

Private Sub HowMany_AfterUpdate()
Select Case HowMany

Case 1
YourField1.Visible = True
YourField2.Visible = False
YourField3.Visible = False
YourField4.Visible = False

Case 2
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = False
YourField4.Visible = False

Case 3
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = True
YourField4.Visible = False

Case 4
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = True
YourField4.Visible = True

Case Else 'If something other than 1-4 is entered nothing shows
YourField1.Visible = False
YourField2.Visible = False
YourField3.Visible = False
YourField4.Visible = False
End Select

End Sub


And then, for when you later view a record, so that the textboxes are
visible/aren’t visble depending

Private Sub Form_Current()

Select Case HowMany

Case 1
YourField1.Visible = True
YourField2.Visible = False
YourField3.Visible = False
YourField4.Visible = False

Case 2
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = False
YourField4.Visible = False

Case 3
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = True
YourField4.Visible = False

Case 4
YourField1.Visible = True
YourField2.Visible = True
YourField3.Visible = True
YourField4.Visible = True

Case Else 'If something other than 1-4 is entered nothing shows
YourField1.Visible = False
YourField2.Visible = False
YourField3.Visible = False
YourField4.Visible = False
End Select

End Sub

'Code ends

Good Luck!

Linq ;0)>

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
Back
Top