Case Statements?

KEKeogh

Registered User.
Local time
Yesterday, 22:19
Joined
May 4, 2011
Messages
80
Hi all!

I have a text box that calculates a child's age and another text box that states whether that child needs a carseat or booster seat.

What I want is the text box for carseat to automatically calculate based on the number in the Age text box.

Normally I use something like the below in other programs but am at a loss as to how to incorporate this into an Access 2000 form.

CASE
IF [Age] = 1 THEN [Car Seat] = “Carseat”
IF [Age] = 2 THEN [Car Seat] = “Carseat”
IF [Age] = 3 THEN [Car Seat] = “Carseat”
IF [Age] = 4 THEN [Car Seat] = “Carseat”
IF [Age] = 5 THEN [Car Seat] = “Booster”
IF [Age] = 6 THEN [Car Seat] = “Booster”
IF [Age] = 7 THEN [Car Seat] = “Booster”
IF [Age] = 8 THEN [Car Seat] = “Booster”
ELSE "None"

Any help is appreaciated.

Thanks
Kathie
 
Assuming that your controls are named "Age" and "Car Seat", in this case you can just use an "IF" statement to do the same thing.

You will need to use some event to trigger the populating of the "Car Seat" text box. You did not indicate what action is causing the "Age" to populated. If the value for the "Age" control is just being entered by the user then you can add the code below to the After Update event of the Age control.

Code:
If Me.Age <= 4 then
     Me.Car_Seat = "Carseat"
Else
     Me.Car_Seat = "[FONT=Times New Roman][SIZE=3]Booster[/SIZE][/FONT]"
Endif
 
Thinking outside (inside actually) of the box.

CarSeat Control properties:
RecordSource:
Code:
=([Age] \ 4) - 1
Be sure to use the backslash (integer divide operator)

Format:
Code:
"None";"CarSeat";"Booster"
 
Last edited:
I would use something like the after update event to use either an if statement or case statement to place in the option that you want.

Behind the Age text box in the properties on the After Update Event place something like this in

Private Sub ChildAge_AfterUpdate()
Select Case ChildAge
Case 1 To 4
CarSeatType = "Carseat"
Case 5 To 8
CarSeatType = "Booster"
Case Else
CarSeatType = "No Age"
End Select
 

Users who are viewing this thread

Back
Top Bottom