Code to change label depending on txt box contents

N

Noel

Hi. I have a text box called txtCount and its label is
called lblCount. How would I organise it so that the label
reads Student if the content of the text box is 1 and
reads Students if the content is 2 or more? Presuming this
would be an Event Code, which Event would I use? Thanks,
Noel
 
M

Marshall Barton

Noel said:
Hi. I have a text box called txtCount and its label is
called lblCount. How would I organise it so that the label
reads Student if the content of the text box is 1 and
reads Students if the content is 2 or more? Presuming this
would be an Event Code, which Event would I use?


You could use the text box's AfterUpdate and the form's
Current event to run code like:

If Me.txtCount = 1 Then
Me.lblCount.Caption = "Student"
Else
Me.lblCount.Caption = "Students"
End If

Or you could do it without using any code by changing the
label to a text box with the equivalent expression:

="Student" & IIf(txtCount = 1, "", "s")
 
N

Noel

Excellent. Thank you very much for the prompt and
comprehensive reply. Cheers, Noel
 

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