Make labels visible/invisible when a text field is filled in/chang

R

RemySS

Hi all,

I have a text field, and two icon labels pasted from the symbols in Word
(one a tick, the other a cross) on my form. I want the cross to be visible
when the field is blank (this includes when the form is closed and opened
again) and the tick to be visible when the field has data in it (in this case
I have a date input mask, e.g. 21/09/2005). Of course, I dont want the labels
to be visible at the same time.

p.s. in the icons labels properties dialog box, the class is
"Word.Document.8" if that makes any difference.

The code i tried to do this with is below:

Private Sub Completed_F10_Issued_to_HSE_Change()

If Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE] = Blank Then

Form_South_Tracker_Rollout.Yes2.Visible = False
Form_South_Tracker_Rollout.No2.Visible = True
Else
Form_South_Tracker_Rollout.Yes2.Visible = True
Form_South_Tracker_Rollout.No2.Visible = False
End If
End Sub

I placed this in the text fields On Change event. This works in a way, but
doesnt update when the form is reloaded, nor does it change if i make the
text field blank again. I'm sure its really simple but my VB is amatuer
level, could anyone help?

Thanks in Advance,
 
S

Sprinks

"Blank" will be interpreted by Access as a variable, as it has no meaning in
VBA. Change the If statement to:

If Nz(Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE]) = 0

You will also need the identical code in the form's On Current event
procedure so that the control's status is updated when you move to a new
record.

Sprinks
 
K

Klatuu

First , the change event is not the correct place to put this. The change
event fires every time the control changes. That means every keystroke
causes the Change event to fire. You need code in two places. In the After
Update event of the control, and in the Current event of the form.
One thing regarding your naming. Since this code is in the Form's module,
full qualification of the control is not necessary. It can be addressed as:
Me.Completed_F10_Issued_to_HSE

So, in the form Cuirrent event:

Me.No2.Visible = IsNull(Me.Completed_F10_Issued_to_HSE)
Me.No3.Visible = Not IsNull(Me.Completed_F10_Issued_to_HSE)

The above will display the correct icon regardless of whether it is a new
record, an existing record with data or an existing record without data.
Now, put the same code in the After Update event of
Completed_F10_Issued_to_HSE.
 
R

RemySS

Brilliant!

Thanks to both Klatuu and Sprinks - both ways worked fine and I'm going to
use them both!

Remy

Klatuu said:
First , the change event is not the correct place to put this. The change
event fires every time the control changes. That means every keystroke
causes the Change event to fire. You need code in two places. In the After
Update event of the control, and in the Current event of the form.
One thing regarding your naming. Since this code is in the Form's module,
full qualification of the control is not necessary. It can be addressed as:
Me.Completed_F10_Issued_to_HSE

So, in the form Cuirrent event:

Me.No2.Visible = IsNull(Me.Completed_F10_Issued_to_HSE)
Me.No3.Visible = Not IsNull(Me.Completed_F10_Issued_to_HSE)

The above will display the correct icon regardless of whether it is a new
record, an existing record with data or an existing record without data.
Now, put the same code in the After Update event of
Completed_F10_Issued_to_HSE.

RemySS said:
Hi all,

I have a text field, and two icon labels pasted from the symbols in Word
(one a tick, the other a cross) on my form. I want the cross to be visible
when the field is blank (this includes when the form is closed and opened
again) and the tick to be visible when the field has data in it (in this case
I have a date input mask, e.g. 21/09/2005). Of course, I dont want the labels
to be visible at the same time.

p.s. in the icons labels properties dialog box, the class is
"Word.Document.8" if that makes any difference.

The code i tried to do this with is below:

Private Sub Completed_F10_Issued_to_HSE_Change()

If Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE] = Blank Then

Form_South_Tracker_Rollout.Yes2.Visible = False
Form_South_Tracker_Rollout.No2.Visible = True
Else
Form_South_Tracker_Rollout.Yes2.Visible = True
Form_South_Tracker_Rollout.No2.Visible = False
End If
End Sub

I placed this in the text fields On Change event. This works in a way, but
doesnt update when the form is reloaded, nor does it change if i make the
text field blank again. I'm sure its really simple but my VB is amatuer
level, could anyone help?

Thanks in Advance,
 
A

Alex Dybenko

Hi,
you can add a call to Completed_F10_Issued_to_HSE_Change to form's open
event

also you can perhaps replace
If Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE] = Blank
to
If is null(Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE])

or
If len(Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE]) = 0
 
R

RemySS

Ok Thanks!

Alex Dybenko said:
Hi,
you can add a call to Completed_F10_Issued_to_HSE_Change to form's open
event

also you can perhaps replace
If Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE] = Blank
to
If is null(Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE])

or
If len(Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE]) = 0

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


RemySS said:
Hi all,

I have a text field, and two icon labels pasted from the symbols in Word
(one a tick, the other a cross) on my form. I want the cross to be visible
when the field is blank (this includes when the form is closed and opened
again) and the tick to be visible when the field has data in it (in this
case
I have a date input mask, e.g. 21/09/2005). Of course, I dont want the
labels
to be visible at the same time.

p.s. in the icons labels properties dialog box, the class is
"Word.Document.8" if that makes any difference.

The code i tried to do this with is below:

Private Sub Completed_F10_Issued_to_HSE_Change()

If Forms![South_Tracker_Rollout].[Completed_F10_Issued_to_HSE] = Blank
Then

Form_South_Tracker_Rollout.Yes2.Visible = False
Form_South_Tracker_Rollout.No2.Visible = True
Else
Form_South_Tracker_Rollout.Yes2.Visible = True
Form_South_Tracker_Rollout.No2.Visible = False
End If
End Sub

I placed this in the text fields On Change event. This works in a way, but
doesnt update when the form is reloaded, nor does it change if i make the
text field blank again. I'm sure its really simple but my VB is amatuer
level, could anyone help?

Thanks in Advance,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top