If Then statement on a report?

kbrooks

Still learning
Local time
Today, 15:34
Joined
May 15, 2001
Messages
202
This is probably insanely simple, but I just can't figure it out.

We have a field called Gender, the values are either M or F. We have a report formatted to look like a letter. I want to put a field on the report that will look at this gender field and put either "Dear Ms." or "Dear Mr." But I can't quite figure out how to do it.

I found an IIf statement that I changed to suit my fields, but there wasn't 2 parts of the If statement. I could get it to put in "Dear Ms." if gender=F, and put "Dear Mr." on all others. But I want to specify only if gender=M, in case they leave it blank or whatever.
 
This is probably insanely simple, but I just can't figure it out.

We have a field called Gender, the values are either M or F. We have a report formatted to look like a letter. I want to put a field on the report that will look at this gender field and put either "Dear Ms." or "Dear Mr." But I can't quite figure out how to do it.

I found an IIf statement that I changed to suit my fields, but there wasn't 2 parts of the If statement. I could get it to put in "Dear Ms." if gender=F, and put "Dear Mr." on all others. But I want to specify only if gender=M, in case they leave it blank or whatever.

You can use a Compound IIf to handle this.
Code:
"Dear " & IIf(Gender="F", "Ms. ", IIf(Gender="M", "Mr. ", "")) & LastName & ","

Compound IIf Statyements are good for a few levels, but if you need more than 4 levels, you might want to consider a Switch() Statement instead.
 
Last edited:
I had got something to work just after posting, but this is bee-YOO-tee-full compared to what I had. Thank you very much!
 
I had got something to work just after posting, but this is bee-YOO-tee-full compared to what I had. Thank you very much!

Glad to help out. Good luck with your projects, and remember the comment about Switch() in my last post
 

Users who are viewing this thread

Back
Top Bottom