a control visibility

  • Thread starter Thread starter \Allen Iverson\
  • Start date Start date
A

\Allen Iverson\

Hi,

I want to write a form so that a control visibility depends on
the control value. In other words,

if control = emtpy string then control visibility = no.

I tried to do this on format event but doesn't work. Can anyone
please advise me which event I should trigger and the proper coding? Thanks.

Mine is:

if control.Value = " " then control.Visible = "No"

But this is not working.
 
Allen,

The event to use is the form's On Current event. The code syntax is:

If IsNull(Me.ConrtolName) Or Me.ControlName = "" Then
Me.ControlName.Visible = False
Else
Me.ControlName.Visible = True
End If

Just change ControlName to the actual name of the control.

HTH,
Nikos
 
Replied in Forms NG.

Please do not multi-post, it's confusing for everyone. In the rare
occasion it is necessary to post to several groups, cross-post unstead
(post once with all the NG names in the recipient box).
 
Allen,

Me.NameOfControl.Visible = Me.NameOfControl = ""

For one thing, your code was testing for a space.

The Current event of the form is probably the appropriate place. Maybe
the After Update event of the control itself too. But I have a couple
of questions...
- Are you sure it will contain a zero-length string, as against being
Null? Empty strings are in my experience quite unusual, and to be
avoided in my opinion.
- If the control is invisible, how are you ever going to get some data
in there?
 
You could use the Nz function, as in:

Me.NameOfControl.Visible = (Nz(Me.NameOfControl) = "")

Nz converts null values to empty strings. This way your code would catch
either empty strings OR null values.

I assume you're using the form to view this particular control, not modify
it. Otherwise, Steve is right--how will you get any data in there??

Joe
 
Joe,

You would need to specify the "value if null", like this...
Me.NameOfControl.Visible = (Nz(Me.NameOfControl,"") = "")
 
Back
Top