Visible Property

  • Thread starter Thread starter Jonathan Smith
  • Start date Start date
J

Jonathan Smith

I am using Access 2002, in a Multi-User, Windows XP Client/Small Business
Server 2000 environment.

I have a form, bound to a table that has the following text fields:

txtDiscipline
txt1
txt2
txt3
txt4
txt5


I want the visibility of txt1 through txt5 to be dependant upon the value
in txtDiscipline. I have initially set the Visible to False in the
Property Sheet of each field. Upon updating txtDiscipline, I would like
the appropriate fields to become visible, and available for User Input.

In the AfterUpdate property of txtDiscipline, I have the following:

If ("txtDiscipline") = OT Then ("txt1").Visible = True
If ("txtDiscipline") = PT Then ("txt2").Visible = True
If ("txtDiscipline") = PT Then ("txt3").Visible = True
If ("txtDiscipline") = ST Then ("txt4").Visible = True
If ("txtDiscipline") = ST Then ("txt5").Visible = True

The above CODE does not return the expected result of the fields becoming
visible given the content of txtDiscipline.

Any help would be appreciated.

Jon
 
Jonathan,

Try this ...

If Me!txtDiscipline = "OT" Then Me!txt1.Visible = True


hth,
 
Try something like this for the AfterUpdate event's code:

Private Sub txtDiscipline_AfterUpdate()
Select Case Me.txtDiscipline.Value
Case "OT"
Me.txt1.Visible = True
Me.txt2.Visible = False
Me.txt3.Visible = False
Me.txt4.Visible = False
Me.txt5.Visible = False
Case "PT"
Me.txt1.Visible = False
Me.txt2.Visible = True
Me.txt3.Visible = True
Me.txt4.Visible = False
Me.txt5.Visible = False
Case "ST"
Me.txt1.Visible = False
Me.txt2.Visible = False
Me.txt3.Visible = False
Me.txt4.Visible = True
Me.txt5.Visible = True
End Select
End Sub

I've written the code so that, if you choose a different value in the
textbox, the other textboxes that were made visible then are made invisible.
Otherwise, your code simply makes things visible, and if you entered the
three different values at separate times while the form remains open, all
five textboxes would be visible.


The reason your code didn't work is that you haven't properly referred to
the controls, and you're not checking for a text string as the value. Your
code could be changed to this:
If Me.txtDiscipline = "OT" Then Me.txt1.Visible = True
If Me.txtDiscipline = "PT" Then Me.txt2.Visible = True
If Me.txtDiscipline = "PT" Then Me.txt3.Visible = True
If Me.txtDiscipline = "ST" Then Me.txt4.Visible = True
If Me.txtDiscipline = "ST" Then Me.txt5.Visible = True

Alternative ways of writing your code are this:

If Me!txtDiscipline = "OT" Then Me!txt1.Visible = True
If Me!txtDiscipline = "PT" Then Me!txt2.Visible = True
If Me!txtDiscipline = "PT" Then Me!txt3.Visible = True
If Me!txtDiscipline = "ST" Then Me!txt4.Visible = True
If Me!txtDiscipline = "ST" Then Me!txt5.Visible = True

If Me.txtDiscipline.Value = "OT" Then Me.txt1.Visible = True
If Me.txtDiscipline.Value = "PT" Then Me.txt2.Visible = True
If Me.txtDiscipline.Value = "PT" Then Me.txt3.Visible = True
If Me.txtDiscipline.Value = "ST" Then Me.txt4.Visible = True
If Me.txtDiscipline.Value = "ST" Then Me.txt5.Visible = True

If Me!txtDiscipline.Value = "OT" Then Me.txt1.Visible = True
If Me!txtDiscipline.Value = "PT" Then Me.txt2.Visible = True
If Me!txtDiscipline.Value = "PT" Then Me.txt3.Visible = True
If Me!txtDiscipline.Value = "ST" Then Me.txt4.Visible = True
If Me!txtDiscipline.Value = "ST" Then Me.txt5.Visible = True

If Me.Controls("txtDiscipline").Value = "OT" Then
Me.Controls("txt1").Visible = True
If Me.Controls("txtDiscipline").Value = "PT" Then
Me.Controls("txt2").Visible = True
If Me.Controls("txtDiscipline").Value = "PT" Then
Me.Controls("txt3").Visible = True
If Me.Controls("txtDiscipline").Value = "ST" Then
Me.Controls("txt4").Visible = True
If Me.Controls("txtDiscipline").Value = "ST" Then
Me.Controls("txt5").Visible = True
 
Try something like this for the AfterUpdate event's code:

Private Sub txtDiscipline_AfterUpdate()
Select Case Me.txtDiscipline.Value
Case "OT"
Me.txt1.Visible = True
Me.txt2.Visible = False
Me.txt3.Visible = False
Me.txt4.Visible = False
Me.txt5.Visible = False
Case "PT"
Me.txt1.Visible = False
Me.txt2.Visible = True
Me.txt3.Visible = True
Me.txt4.Visible = False
Me.txt5.Visible = False
Case "ST"
Me.txt1.Visible = False
Me.txt2.Visible = False
Me.txt3.Visible = False
Me.txt4.Visible = True
Me.txt5.Visible = True
End Select
End Sub

I've written the code so that, if you choose a different value in the
textbox, the other textboxes that were made visible then are made
invisible. Otherwise, your code simply makes things visible, and if
you entered the three different values at separate times while the
form remains open, all five textboxes would be visible.


The reason your code didn't work is that you haven't properly referred
to the controls, and you're not checking for a text string as the
value. Your code could be changed to this:
If Me.txtDiscipline = "OT" Then Me.txt1.Visible = True
If Me.txtDiscipline = "PT" Then Me.txt2.Visible = True
If Me.txtDiscipline = "PT" Then Me.txt3.Visible = True
If Me.txtDiscipline = "ST" Then Me.txt4.Visible = True
If Me.txtDiscipline = "ST" Then Me.txt5.Visible = True

Alternative ways of writing your code are this:

If Me!txtDiscipline = "OT" Then Me!txt1.Visible = True
If Me!txtDiscipline = "PT" Then Me!txt2.Visible = True
If Me!txtDiscipline = "PT" Then Me!txt3.Visible = True
If Me!txtDiscipline = "ST" Then Me!txt4.Visible = True
If Me!txtDiscipline = "ST" Then Me!txt5.Visible = True

If Me.txtDiscipline.Value = "OT" Then Me.txt1.Visible = True
If Me.txtDiscipline.Value = "PT" Then Me.txt2.Visible = True
If Me.txtDiscipline.Value = "PT" Then Me.txt3.Visible = True
If Me.txtDiscipline.Value = "ST" Then Me.txt4.Visible = True
If Me.txtDiscipline.Value = "ST" Then Me.txt5.Visible = True

If Me!txtDiscipline.Value = "OT" Then Me.txt1.Visible = True
If Me!txtDiscipline.Value = "PT" Then Me.txt2.Visible = True
If Me!txtDiscipline.Value = "PT" Then Me.txt3.Visible = True
If Me!txtDiscipline.Value = "ST" Then Me.txt4.Visible = True
If Me!txtDiscipline.Value = "ST" Then Me.txt5.Visible = True

If Me.Controls("txtDiscipline").Value = "OT" Then
Me.Controls("txt1").Visible = True
If Me.Controls("txtDiscipline").Value = "PT" Then
Me.Controls("txt2").Visible = True
If Me.Controls("txtDiscipline").Value = "PT" Then
Me.Controls("txt3").Visible = True
If Me.Controls("txtDiscipline").Value = "ST" Then
Me.Controls("txt4").Visible = True
If Me.Controls("txtDiscipline").Value = "ST" Then
Me.Controls("txt5").Visible = True

Awesome response. Thank you very much.
 
You might want to take a different approach to this. When txtDiscipline is
updated a second time you probably want the text boxes that were made
visible the first time to become invisible again. To do this you could try
something like this:

txt1.visible = (txtDiscipline = "OT")
txt2.visible = (txtDiscipline = "PT")
txt3.visible = (txtDiscipline = "PT")
txt4.visible = (txtDiscipline = "ST")
txt5.visible = (txtDiscipline = "ST")
 
Back
Top