Hiding Line

B

briank

I am trying to make a line hidden or visible based upon the value of a text
field. My code isn't working. It is my goal that is text57 returns the
value of "Closed" then the line is hidden - if not then it is visible. Any
help is appreciated.

Private Sub Form_Current()
If Me.Text57.Text = Closed Then
Me.Line65.Visible = False
Else
Me.Line65.Visible = True
End If

End Sub
 
A

Andy Williams

You haven't said what is actually happening but one thing that strikes me is
that Closed should be in speech marks like this:-

If Me.Text57.Text = "Closed" Then
 
B

briank

The problem is that the line is not changing from visible to hidden. If
text57 equals "Closed" then the line is still visible. I did input alter the
text to include the quotes but still no changes. There appears to be no
error messages or anyother indicators to help base the problem. I'm stumped.
 
K

Klatuu

Unlike VB, the Text property of a control is valid only if the control has
the focus. You need to leave it off:
If Me.Text57 = "Closed" Then
Me.Line65.Visible = False
Else
Me.Line65.Visible = True
End If

or

Me.Line65.Visible = (Me.Text57 <> "Closed")
 
A

Andy Williams

The problem is that the Current event only triggers each time you change
records it doesn't trigger if you update a particular field in a record so
when the forms is open it accesses record 1 and that triggers the Current
event but if you then update Text57 so that it says "Closed" that doesn't
cause the Current event to trigger.

I'm not sure how your using the form so this may not work but you could try
using the After_Update event of Text57 so that if it changes it will always
do the check to see if it's value is "Closed".
 
K

Klatuu

It actually needs to be in both places so it will show correctly for existing
records. Another thing I found in testing this is it is necessary to set the
line's visible property to No in design view.
 
B

briank

The line is showing if the condition is true and hidden if false. Thank you
both for your help.
 
Top