Many checkboxes to one label

K

kumba

I'm a novice to MS Access and would truly appreciate any feedback/help
that is offered. Here is my situation:
I have 5 different checkboxes that produce true/false "make label
visible" results to the same label. The label becomes visible when the
checkbox is checked but when I reopen the database, the box is checked
but the label is not visible. I've tried refreshing the form before
saving but with the same results.

Here is the code for each checkbox:

Private Sub Question1_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question1
End Sub

Private Sub Question2_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question2
End Sub

Private Sub Question3_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question3
End Sub

Private Sub Question4_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question4
End Sub

Private Sub Question5_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question5
End Sub

Here is the code for the form:

Private Sub Form_Current()
Me.Unable_Hire.Visible = Me.Question1
Me.Unable_Hire.Visible = Me.Question2
Me.Unable_Hire.Visible = Me.Question3
Me.Unable_Hire.Visible = Me.Question4
Me.Unable_Hire.Visible = Me.Question5
End Sub

I'm assuming I'm missing something on the Form_Current() section but
have no idea what it is.....

Thanks in advance,
MK
 
T

TC

That form-current code should work fine. All I can suggest is, to
display the value of one of the questions (from that event) to check
that it is what you think it is.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
T

TC

PS. Also try this. Put a msgbox in form-current to see if that code is
actally being executed at all!. If it /isn't/ - select all the code in
the form module, type ctrl-x to cut, ctrl-v to paste back, then save
the module & try again. This will reconnect all event code to the
corresponding events. The code can get disconnected from the event, in
certain cases.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
G

Guest

The results from the OnCurrent event of your form will always set the
visibility of your lable to be equal to the status of the Me.Question5
checkbox because it is the last evaluation made. The other checkboxes could
be true and the result would be the same. You may have to use individual If
statements.
 
K

kumba

I tried using If/Then statements but still seem to run into the same
problem of the label not being visible on some questions when the
database is opened. Here is the code I put in(form_current):

Private Sub Form_Current()
If [Question1] = True Then
[Unable_Hire].Visible = True
Else
[Unable_Hire].Visible = False
End If
If [Question2] = True Then
[Unable_Hire].Visible = True
Else
[Unable_Hire].Visible = False
End If
If [Question3] = True Then
[Unable_Hire].Visible = True
Else
[Unable_Hire].Visible = False
End If
If [Question4] = True Then
[Unable_Hire].Visible = True
Else
[Unable_Hire].Visible = False
End If
If [Question5] = True Then
[Unable_Hire].Visible = True
Else
[Unable_Hire].Visible = False
End If
End Sub

Thanks,
MK
 
T

TC

Mr B explained it. You are repeatedly setting the visibility of *the
same control*, [Unable_Hire].

1> You set the visibility of that control, depending on the value of
Question1.

2> You set the visibily of *the same control*, depending on the value
of Question2. So what you did in 1>, is now *irrelevant*.

3> You set the visibily of *the same control*, depending on the value
of Question3. So what you did in 1> and 2, are now irrelevant,
and so on.

Finally, you set the visbility *of the same control*, depending on the
value of Question5. So that is the final result that you see on the
screen! All of the previous code, is irelevant.

Do you see it now?

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
K

kumba

Thanks so much!....so basically I'm running in a redundant circle. How
do I get out of this viscous cycle? Do I need to make more copies of
the same label and rename each individually different?

Thanks again,
MK
 
T

TC

The way you had it in your original post was fine - if you create >>> a
seperate control for each question <<<.

Like this:

Private Sub Question1_AfterUpdate()
Me.Unable_Hire.Visible = Me.Question1
End Sub

Private Sub Question2_AfterUpdate()
' **** Do not use [Unable_Hire] again here - have seperate control to
show Question 2. ***
Me.Unable_Hire.Visible = Me.Question2
End Sub

Private Sub Question3_AfterUpdate()
' **** Do not use [Unable_Hire] again here - have seperate control to
show Question 3. ***
Me.Unable_Hire.Visible = Me.Question3
End Sub

(etc.)

Private Sub Form_Current()
Me.Unable_Hire.Visible = Me.Question1
' **** Use the seperate control for Question 2 next. ***
Me.Unable_Hire.Visible = Me.Question2
' **** Use the seperate control for Question 3 next. ***
Me.Unable_Hire.Visible = Me.Question3

(etc.)

End Sub

HTH,
TC (MVP Access)
http://tc2.atspace.com
(off for a while)
 
K

kumba

I really hope that I don't wear your patience thin here but I really
stink at this! The 5 questions/checkboxes are named Question1 thru
Question5. I'm not grasping the "seperate control" issue because I
thought that the control sources were different (Question1, Question2,
etc...) Would it be easier to make copies of "Unable_Hire" and name
them individually (Unable_Hire1, Unable_Hire2, etc...) and have them
referred to in the code?

One code at a time....
Mk
 
T

TC

Ok, I'm back for a few moments only!

You said in your original post: "I have 5 different checkboxes ...". I
assume that those are for the 5 different question fields Question1
thru Question5 that you have in your table? If so:

- You can name each checkbox *control*, whatever you want. But a
regular scheme, such as, chkQuestion1 through chkQuestion5, would be
best.

- You set the ControlSource property of each checkbox control, to the
name of the corresponding field in the table. This connects or "binds"
that control, to that field. So, you'd set the ControlSource property
of the chkQuestion1 control, to "Question1" without the quotes, and so
on.

Correct?

Next, you said that the 5 checkboxes "produce true/false 'make label
visible' results to the same label. The label becomes visible when the
checkbox is checked".

That's the bit I don't understand. Do you want:

(1) A single label - just one - which is made visible depending on the
settings of the various checkboxes? Or,

(2) 5 labels - one for each checkbox? So a given label is made visible
if the corresponding checkbox is visible?

I've re-read your original post a few times, and I'm not sure whether
you want (1) or (2). Clarify that, then I can tell you how to achieve
it.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
K

kumba

The result I'm looking for is:
(1) A single label - just one - which is made visible depending on the
settings of the various checkboxes

MK
 
T

TC

Ok - now we're there!

Sorry this is taking a while, I've had other things that I had to
attend to.

The only remaining question is, how do you want the settings of the
*five* question fields, to affect the visibility of the *one* label?
For example, should the label only be visible when *all* of the 5
question fields are True? Or should it be visible when *any* of those
fields are true?

To make a label control named lblBlah visible when *all* of the 5
question fields are true:

Me![lblBlah].Visible = (Me![Question1] AND Me![Question2] AND
Me![Question3] AND Me![Question4] AND Me![Question5])

To make that control visible when *any* of the 5 question fields are
true:

(as above, with OR instead of AND)

Does that help?

I'm having some heavy-duty dental work tomorrow, so unfortunately I
will not see your reply until the morning after tomorrow.

Cheers,
TC (MVP Access)
http://tc2.atspace.com
 
K

kumba

Still having problems.....I keep getting "Compile Error, Expected:
expression"
This is how I put the code in:

Private Sub Form_Current()
Me![Unable_Hire].Visible = (Me![Question1] Or Me![Question2] Or
Me![Question3] Or Me![Question4] Or Me![Question5])
End Sub

Good luck at the dentist, I was there a few weeks back and luckily he
was outstanding.
MK
 
D

Douglas J. Steele

Did you type that all on one line?

If not, you need to use a line continuation character:

Private Sub Form_Current()

Me![Unable_Hire].Visible = (Me![Question1] Or _
Me![Question2] Or Me![Question3] Or _
Me![Question4] Or Me![Question5])

End Sub
 
K

kumba

Thanks a bunch....I think that did it. You guys taking the time to
answer these does not go unappreciated.

Thanks again,
MK
 
K

kumba

WAIT!!!!!!!!! There is one last problem. I'm getting a runtime error
and I think it is because I didn't put an option on the "not visible"
portion (if none of the checkboxes are checked) at the end of the
statement. Do I need and IF/ELSE statement there?

Private Sub Form_Current()
Me.Unable_Hire.Visible = (Me![Question1] Or _
Me![Question2] Or Me![Question3] Or _
Me![Question4] Or Me![Question5])
End Sub

Thanks
Kumba
 
D

Douglas J. Steele

You shouldn't need an IF/ELSE. If none of the checkboxes are checked, the OR
will evaluate to False, so the control won't be visible. If any are checked,
the OR will evaluate to True, so it will be.

Is it possible that one (or more) of the checkboxes are Null (greyed out)?

Try:

Private Sub Form_Current()

Me.Unable_Hire.Visible = _
(Nz(Me![Question1], False) Or _
Nz(Me![Question2], False) Or _
Nz(Me![Question3], False) Or _
Nz(Me![Question4], False) Or _
Nz(Me![Question5], False))

End Sub
 

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