If a field = 0 then display text?

Is there a way in access to display certain text if a field = a certain number. For example if PH_STATUS = 0 then display closed IF PH_STATUS = 1 then display OPEN. I am not sure how to do this within access. Any help would be much appreciated!
HOTWATTAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
You can use the IIF() function, in a query.

If the valuses are always either 0 or 1 then:

IIF(PH_STATUS = 1, 'OPEN', 'CLOSED')

If there can be other values then:

IIF(PH_STATUS = 1, 'OPEN', IIF(PH_STATUS = 0, 'CLOSED', ''))


»bp
0
 
Dustin SaundersDirector of OperationsCommented:
There are a couple of ways to do that, but the better question is:

Are there only 2 statuses or are there multiple ones?

You will probably want a separate table for your statuses and then you can reference those values on your display.  Is that the case?
0
 
Dale FyeConnect With a Mentor Commented:
in a textbox, you can set the ControlSource to:

=IIF([PH_Status]=0, 'Closed', 'Open')

But if you are talking about hiding a field based on the value of [PH_Status] you would have to use the FORM_Current and AfterUpdate event of the control that contains the value for [PH_Status] to then hide/reveal some other control, something like:

Private Sub txt_PH_Status_AfterUpdate

    me.SomeControlName.Visible = ([PH_Status] = 1)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
HOTWATTAuthor Commented:
there are more statuses but we are just looking at closed and open right now which are 0 and 1
0
 
HOTWATTAuthor Commented:
Thanks for the help! Bill that worked perfectly!
0
 
Bill PrewCommented:
Great, glad that helped.


»bp
0
 
Dustin SaundersDirector of OperationsCommented:
there are more statuses but we are just looking at closed and open right now which are 0 and 1

You should go ahead and design your form to accommodate this then.  Rather than a text field, you should make that a combo box that contains your status values, a few reasons off the cuff:

>You can add new statuses easily when needed.
>You can retire old statuses and retain their value as it was if desired by adding an 'Active' column to your statuses.
>Without this, any form you implement changes on will not be the same as others.  You have to go touch EACH place you have that condition.
>The combo box enforces data validation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.