Check Box - text to appear

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm a beginner/intermediate user of Access 2002 (Doing a lot of self
teaching!)

I want text to appear on a form when the check box is selected.

The check box is called Cancelled and the label is called Label166.

I understand that I need to put a formula in After Update on the check box
properties, but don't know what to put in it. Could somebody let me know what
I need to do. Thank you very much.

L
 
To show the label when the check box is ticked and hide it when the check
box is cleared ...

Me!Label166.Visible = (Me!Canelled)

If you want to display different text depending on whether the check box is
ticked or cleared ...

If (Me!Cancelled) Then
Me!Label166.Caption = "You checked it"
Else
Me!Label166.Caption = "You cleared it"
End If

In theory, the parentheses around "Me!Cancelled" in the examples above
shouldn't be needed, but there was a bug in at least some versions of Access
that could cause Access to fail to close properly when you executed code
like "If Me!SomeCheckBox Then". The parentheses - e.g "If (Me!SomeCheckBox)
Then" - are one way of avoiding that bug.
 
L said:
Hi,

I'm a beginner/intermediate user of Access 2002 (Doing a lot of self
teaching!)

I want text to appear on a form when the check box is selected.

The check box is called Cancelled and the label is called Label166.

I understand that I need to put a formula in After Update on the check box
properties, but don't know what to put in it. Could somebody let me know
what
I need to do. Thank you very much.
Something like this should do it (untested):

Sub ShowLegend

If Me.Cancelled Then
Me.Label166.Visible = True
Else
Me.Label166.Visible = False
End If
Me.Refresh

End Sub

Then call the sub from the check box Update event and the form's Current
event. I'd also put a Refresh command in the check box Update event after
the call.

Incidentally, it's considered to be good practice to identify object in code
such that the names mean something to you. As your code grows and becomes
more complex you'll be glad you did:

If Me.chkCancelled Then
Me.lblLegend.Visible = True
Else
Me.lblLegend.Visible = False
End If

HTH - Keith.
www.keithwilby.com
 
Hi,

Thank you for your reply. I have entered the formula you suggested, but it
does appear to work. The text I want to appear appears all the time and when
I tick and untick the check box, the following message appears:

"The expression After Update you entered as the event property setting
produced the following error: The object doesn't contain the automation
object 'Me.'.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.


I have no idea what this means. I don't know anything about Macros.
Beginners eh?!!! :)
 
Perhaps you did not enter the code in the correct place. You need to click
the 'builder' button - the one with the ellipsis (...) - to the right of the
'After Update' field in the Properties window, then if prompted to 'Choose
Builder' choose 'Code Builder' and add the new code between the 'Sub ... '
and 'End Sub' lines.

If you already entered something directly in the 'After Update' field in the
Properties window, you may need to delete that first.

--
Brendan Reynolds


L said:
Hi,

Thank you for your reply. I have entered the formula you suggested, but it
does appear to work. The text I want to appear appears all the time and
when
I tick and untick the check box, the following message appears:

"The expression After Update you entered as the event property setting
produced the following error: The object doesn't contain the automation
object 'Me.'.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.


I have no idea what this means. I don't know anything about Macros.
Beginners eh?!!! :)




Brendan Reynolds said:
To show the label when the check box is ticked and hide it when the check
box is cleared ...

Me!Label166.Visible = (Me!Canelled)

If you want to display different text depending on whether the check box
is
ticked or cleared ...

If (Me!Cancelled) Then
Me!Label166.Caption = "You checked it"
Else
Me!Label166.Caption = "You cleared it"
End If

In theory, the parentheses around "Me!Cancelled" in the examples above
shouldn't be needed, but there was a bug in at least some versions of
Access
that could cause Access to fail to close properly when you executed code
like "If Me!SomeCheckBox Then". The parentheses - e.g "If
(Me!SomeCheckBox)
Then" - are one way of avoiding that bug.
 
Hi,

Thank you for your help. On both yours and Brendan's instructions, I have
put the programming in, but when close the design view, every record shows
the text.....argh! :)
 
Is this a continuous form?

--
Brendan Reynolds


L said:
Hi,

Thank you for your help. On both yours and Brendan's instructions, I have
put the programming in, but when close the design view, every record shows
the text.....argh! :)
 
Yes it is.
It is a form which I use to book training courses booked. One record per
training course.
 
L said:
Yes it is.
It is a form which I use to book training courses booked. One record per
training course.

If you've coded it correctly *all* displayed instances of the label will
change on a per record basis. I think we both assumed it was a single form
type.

Keith.
 
You'll need a different approach, then. Replace the label with a text box,
and enter the following expression as the Control Source property of the
text box ...

=IIf([Cancelled]=True,"Some Text","")

That's not a typo - there really are two i's in "IIf" - see "IIf Function"
in the help file for details.

Replace "Some Text" with the text you want to display if the check box is
ticked. Those are two double quotes with nothing between them at the end. If
you want to display different text when the check box is not ticked, enter
that text between those two double quotes. If you want to display nothing
when the check box is not ticked, leave the two double quotes at the end as
they are, with nothing between them.
 
Wow - it works! Thank you so much!!!!



Brendan Reynolds said:
You'll need a different approach, then. Replace the label with a text box,
and enter the following expression as the Control Source property of the
text box ...

=IIf([Cancelled]=True,"Some Text","")

That's not a typo - there really are two i's in "IIf" - see "IIf Function"
in the help file for details.

Replace "Some Text" with the text you want to display if the check box is
ticked. Those are two double quotes with nothing between them at the end. If
you want to display different text when the check box is not ticked, enter
that text between those two double quotes. If you want to display nothing
when the check box is not ticked, leave the two double quotes at the end as
they are, with nothing between them.

--
Brendan Reynolds

L said:
Yes it is.
It is a form which I use to book training courses booked. One record per
training course.
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Back
Top