Code to change label depending on txt box contents

  • Thread starter Thread starter Noel
  • Start date Start date
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
 
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")
 
Back
Top