Show / Hide Fields from a Check Box

  • Thread starter scottypws via AccessMonster.com
  • Start date
S

scottypws via AccessMonster.com

Hello,

I need your assistance regarding the visibility of a field and its associated
label. I want to hide the visibility of a particular label and associated
field for each record from a query that that is the source to the form.

I use the check box named "Grievance_Filed" to activate the visibility of a
particular label and field. Whenever I click the check box the label and
field appears; and when I unchecked the check box, the field and label
disappears. For a single record at the outset when the form opens, this is
no problem.

PROBLEM: When I initially click the check box in the first record, the label
and field appears.
However, when I navigate to the second record, the label and field is visible
even though the check box is not checked.

I thought that setting the visibility to "No" for the field and label would
take care of the problem, but it doesn't.

REQUESTED ASSISTANCE: How to stabilize the visibility for a label and
associated filed to "No" for all records; and only show the visibility when
the check box is checked.


In the Design mode of the form, I have set the Visibility for the following
label and associated field to "No".

lblGrievanceNbr
txtGrievanceNbr


I have embedded the following code in the AfterUpdate event of the check box:

Quote:

Private Sub Grievance_Field_AfterUpdate()

' When checkbox is checked
If Me.Grievance_Field = True Then

' Show the label and field
lblGrievanceNbr.Visible = True
txtGrievanceNbr.Visible = True

Else

'Do not show label and field
lblGrievanceNbr.Visible = False
txtGrievanceNbr.Visible = False

End If
End Sub

Your help is greatly appreciated.

Scotty
 
K

Klatuu

You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


scottypws via AccessMonster.com said:
Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty
Is the check box a bound control?
[quoted text clipped - 51 lines]
 
P

Pattyt

Hi,
I hope you can figure out what I'm doing wrong.
I have a very similar situation, in my case if the check-box value is true
then I want my option group to show otherwise it shouldn't be visible. I
tried putting code in the afterupdate event of my check-box and on the on
current event of my form but when I for instance check the box on the first
record everything works fine but when I go to the next records the check-box
is checked and the option group shows just like the first record. If I
uncheck the box the option group is not visible on all records.
As a note: my check box is bound to a table but my option group is not.

Here is the code I have:
Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
.OptSigAcq.Enabled = .ChckSelfQa1
End With
End Sub



Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1

End If
End With
End Sub

Klatuu said:
You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


scottypws via AccessMonster.com said:
Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty
Is the check box a bound control?
Hello,

[quoted text clipped - 51 lines]

Scotty
 
K

Klatuu

I took this line out, you don't need it:
.OptSigAcq.Enabled = .ChckSelfQa1

Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
End With
End Sub

Now, lets be sure of the naming. OptSigAcq should be the name of the frame
around the options, not the name of one of the options.

I made a minor change here, but I'm not sure it will do any good.

Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = True
.OptSigAcq.Visible = True

End If
End With
End Sub

Other than the naming, I don't see anything obvious. The way the code reads
is if you check the box the label and and option group are visible and when
you uncheck it, they become invisible,

--
Dave Hargis, Microsoft Access MVP


Pattyt said:
Hi,
I hope you can figure out what I'm doing wrong.
I have a very similar situation, in my case if the check-box value is true
then I want my option group to show otherwise it shouldn't be visible. I
tried putting code in the afterupdate event of my check-box and on the on
current event of my form but when I for instance check the box on the first
record everything works fine but when I go to the next records the check-box
is checked and the option group shows just like the first record. If I
uncheck the box the option group is not visible on all records.
As a note: my check box is bound to a table but my option group is not.

Here is the code I have:
Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
.OptSigAcq.Enabled = .ChckSelfQa1
End With
End Sub



Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1

End If
End With
End Sub

Klatuu said:
You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


scottypws via AccessMonster.com said:
Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty

Klatuu wrote:
Is the check box a bound control?
Hello,

[quoted text clipped - 51 lines]

Scotty
 
P

Pattyt

Thank you for your response.
I changed my code to match yours and it still doesn't seem to work. Do you
have any other suggestions?

Klatuu said:
I took this line out, you don't need it:
.OptSigAcq.Enabled = .ChckSelfQa1

Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
End With
End Sub

Now, lets be sure of the naming. OptSigAcq should be the name of the frame
around the options, not the name of one of the options.

I made a minor change here, but I'm not sure it will do any good.

Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = True
.OptSigAcq.Visible = True

End If
End With
End Sub

Other than the naming, I don't see anything obvious. The way the code reads
is if you check the box the label and and option group are visible and when
you uncheck it, they become invisible,

--
Dave Hargis, Microsoft Access MVP


Pattyt said:
Hi,
I hope you can figure out what I'm doing wrong.
I have a very similar situation, in my case if the check-box value is true
then I want my option group to show otherwise it shouldn't be visible. I
tried putting code in the afterupdate event of my check-box and on the on
current event of my form but when I for instance check the box on the first
record everything works fine but when I go to the next records the check-box
is checked and the option group shows just like the first record. If I
uncheck the box the option group is not visible on all records.
As a note: my check box is bound to a table but my option group is not.

Here is the code I have:
Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
.OptSigAcq.Enabled = .ChckSelfQa1
End With
End Sub



Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1

End If
End With
End Sub

Klatuu said:
You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


:

Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty

Klatuu wrote:
Is the check box a bound control?
Hello,

[quoted text clipped - 51 lines]

Scotty
 
P

Pattyt

I figured it out and I thought I should let you know. I feel so dumb about
this but I must have accidently deleted the control source of my check-box. I
have gone back and added the control source again and it is now working
perfectly.

Thank you very much for your help and I apologize for this.
Take care.

Klatuu said:
I took this line out, you don't need it:
.OptSigAcq.Enabled = .ChckSelfQa1

Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
End With
End Sub

Now, lets be sure of the naming. OptSigAcq should be the name of the frame
around the options, not the name of one of the options.

I made a minor change here, but I'm not sure it will do any good.

Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = True
.OptSigAcq.Visible = True

End If
End With
End Sub

Other than the naming, I don't see anything obvious. The way the code reads
is if you check the box the label and and option group are visible and when
you uncheck it, they become invisible,

--
Dave Hargis, Microsoft Access MVP


Pattyt said:
Hi,
I hope you can figure out what I'm doing wrong.
I have a very similar situation, in my case if the check-box value is true
then I want my option group to show otherwise it shouldn't be visible. I
tried putting code in the afterupdate event of my check-box and on the on
current event of my form but when I for instance check the box on the first
record everything works fine but when I go to the next records the check-box
is checked and the option group shows just like the first record. If I
uncheck the box the option group is not visible on all records.
As a note: my check box is bound to a table but my option group is not.

Here is the code I have:
Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
.OptSigAcq.Enabled = .ChckSelfQa1
End With
End Sub



Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1

End If
End With
End Sub

Klatuu said:
You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


:

Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty

Klatuu wrote:
Is the check box a bound control?
Hello,

[quoted text clipped - 51 lines]

Scotty
 
K

Klatuu

Glad you got it working.
Thanks for letting me know. I was getting cross-eyed trying to figure it out.
--
Dave Hargis, Microsoft Access MVP


Pattyt said:
I figured it out and I thought I should let you know. I feel so dumb about
this but I must have accidently deleted the control source of my check-box. I
have gone back and added the control source again and it is now working
perfectly.

Thank you very much for your help and I apologize for this.
Take care.

Klatuu said:
I took this line out, you don't need it:
.OptSigAcq.Enabled = .ChckSelfQa1

Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
End With
End Sub

Now, lets be sure of the naming. OptSigAcq should be the name of the frame
around the options, not the name of one of the options.

I made a minor change here, but I'm not sure it will do any good.

Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = True
.OptSigAcq.Visible = True

End If
End With
End Sub

Other than the naming, I don't see anything obvious. The way the code reads
is if you check the box the label and and option group are visible and when
you uncheck it, they become invisible,

--
Dave Hargis, Microsoft Access MVP


Pattyt said:
Hi,
I hope you can figure out what I'm doing wrong.
I have a very similar situation, in my case if the check-box value is true
then I want my option group to show otherwise it shouldn't be visible. I
tried putting code in the afterupdate event of my check-box and on the on
current event of my form but when I for instance check the box on the first
record everything works fine but when I go to the next records the check-box
is checked and the option group shows just like the first record. If I
uncheck the box the option group is not visible on all records.
As a note: my check box is bound to a table but my option group is not.

Here is the code I have:
Private Sub ChckSelfQa1_AfterUpdate()
With Me
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1
.OptSigAcq.Enabled = .ChckSelfQa1
End With
End Sub



Private Sub Form_Current()
With Me
If .NewRecord Or .ChckSelfQa1 = False Then
.Label107.Visible = False
.OptSigAcq.Visible = False
Else
.Label107.Visible = .ChckSelfQa1
.OptSigAcq.Visible = .ChckSelfQa1

End If
End With
End Sub

:

You need code in two places. First, in the form Current event to set the
visibliity for the current record as well as for new records:

With Me
If .NewRecord Or .Grievance_Filed = True Then
.lblGrievanceNbr.Visible = True
.txtGrievanceNbr.Visible = True
Else
.lblGrievanceNbr.Visible = False
.txtGrievanceNbr.Visible = False
End If
End With

And in the After Update event of the check box to change visibility when the
box is checked or unchecked by the user:

With Me
.lblGrievanceNbr.Visible = .Grievance_Filed
.txtGrievanceNbr.Visible = .Grievance_Filed
End With

--
Dave Hargis, Microsoft Access MVP


:

Yes,

It is a "Yes/No" field type in a table. A query pulls in the table fields as
the source to the form.

Scotty

Klatuu wrote:
Is the check box a bound control?
Hello,

[quoted text clipped - 51 lines]

Scotty
 

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