INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Building custom expression (ms access)

Building custom expression (ms access)

(OP)
Hi,

I have a table with the following fields/values:

Status: open, closed, pending
ClosedReason: 1, 2. 3

If status = closed, then ClosedReason will display one of the numeric values from drop down.
However, I would like to change the query criteria and build expression so that the query returns the text description follows.
1: closed on site
2: closed off site
3: Referred

How can I accomplish the above?

TIA

Regards

OCM

RE: Building custom expression (ms access)

Add the table containing 1: closed on site 2: closed off site 3: Referred to the query. If you don't have a table (maybe not a good idea) you can create an expression using the Choose() function:

CODE --> query

ClosedReasonText: Choose([ClosedReason], "closed on site", "closed off site", "Referred") 

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Building custom expression (ms access)

(OP)
Hi,
Sorry for not clarifying. The table only contains numeric values (no text descriptions). Basically, I want to replace the numeric value with text e.g. if ClosedReason= 1 then display "closed on site", if ClosedReason =2, then show me "closed off site" etc.

TIA

OCM

RE: Building custom expression (ms access)

That's exactly what I provided in the CODE box. You should however make this more flexible by creating a small lookup table. It would have taken less time than replying back.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Building custom expression (ms access)

(OP)
Hi,
I'm relatively new and the db was design by someone else and apparently didn't incorporate the description during the design process.
What I was thinking was to create expression like IIF([ClosedReason] = 1, "Closed on site"....
but wasn't sure about the correct syntax.

TIA

OCM

RE: Building custom expression (ms access)

I gave you the exact syntax using the Choose() function.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Building custom expression (ms access)

Now you are venturing into the VBA world, which has betted help in forum707: VBA Visual Basic for Applications (Microsoft)

So if you have something like this in column A and want this in column B:
     A      B
1    1     closed on site
2    3     Referred
3    2     closed off site
4    1     closed on site
 
You could create a User Defined Function:

CODE --> Module

Public Function ClosedReason(ByRef intIn As Integer) As String
Dim strOut As String

Select Case intIn
    Case 1: strOut = "closed on site"
    Case 2: strOut = "closed off site"
    Case 3: strOut = "Referred"
End Select
ClosedReason = strOut

End Function 

Now you can use your own formula in cell B1: =ClosedReason(A1)

BTW - this is just to prove the VBA route, but you should NOT keep the data in the code. You should have your data in the table in the spreadsheet.

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Building custom expression (ms access)

I agree with Andy except the "spreadsheet" part winky smile

The question should have been posted in one of the MS Access forums based on the subject line.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Building custom expression (ms access)

(OP)
Thank you both for the reply post. Andy, thank you for the vba link as well.
Regards,

OCM

RE: Building custom expression (ms access)

Sorry about the "spreadsheet" part. It is not Excel, it is Access.
If that's the case, the solution is even easier:

Create a table:
ClosedReason
ID   Reason
1    closed on site
2    closed off site
3    Referred
 
And use it in your queries wherever you want to display this information.

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close