Using IIf in a query in Access Database (1 Viewer)

Leah Brayn

New member
Local time
Today, 04:06
Joined
Feb 4, 2013
Messages
5
I have set up a database at work.

I need someone who understands the IIf Function. If someone could help me out by explaining it to me????

I am trying to use this in a word doc.
IIf the field is not blank and IIF the next field is not blank I just want to add dba behind the first field.

I know how to add switches and have used them correctly but I only want to use it IIF the next field is not blank.

If this even possible???? :banghead:
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 04:06
Joined
May 3, 2012
Messages
636
When you say next field do you mean the next Record?
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 04:06
Joined
May 3, 2012
Messages
636
also are you doing a word mail merge from Access?
 

Leah Brayn

New member
Local time
Today, 04:06
Joined
Feb 4, 2013
Messages
5
When I say the next field that is what I mean. Not next record of that field.
But yes, I am doing a work mail merge from Access.
 

plog

Banishment Pending
Local time
Today, 06:06
Joined
May 11, 2011
Messages
11,661
If someone could help me out by explaining it to me????

Its pretty straight forward: http://www.techonthenet.com/access/functions/advanced/iif.php

It has 3 parts, the first part is the condition (aka something that can evaluate to true or false). The 2nd part is what to do if the condition is true, the 3rd part is what to do if the condition is false. These 3 parts are seperated by commas. So the expression

IIF([Field1]>0, "Positive Number", "Non-Positive Number")

Will print out "Positive Number if Field1 has a value greater than 0, and will print out "Non-Positive Number" for any value 0 or less.


I am trying to use this in a word doc.

What is "this"? The query or the IIF statement? Hopefully the query.

IIf the field is not blank and IIF the next field is not blank I just want to add dba behind the first field.

Since this is a technical issue, I need to get nit picky. 'next field' isn't typically a term that is used in databases. Do you actually mean field or row? A field roughly translates into a column of data and a row is a whole seperate record from the one you are viewing. Do you mean 'another field in the same record' or do you mean 'the same field in a different record'?

In either case, to test for a blank value you would use the IsNull function (http://www.techonthenet.com/access/functions/advanced/isnull.php) in your IIF statement. It would look like this:

QueryFieldName: Iif(Isnull([Field1])=False AND Isnull([Field2])=False, [Field1] & "dba")
 

Leah Brayn

New member
Local time
Today, 04:06
Joined
Feb 4, 2013
Messages
5
Chery,
You are so kind to look this over. I appreciate this. I just have never gotten the IIF function to work for me the way that I need it to work.
 

Leah Brayn

New member
Local time
Today, 04:06
Joined
Feb 4, 2013
Messages
5
Oh, I see.
I have a doc. with 2 Columns of data in 2 different places.
I need the first column to add some wording if the 2nd column is not blank.
Does this help explain it any better???
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 04:06
Joined
May 3, 2012
Messages
636
Put this in your query for column 1
=iif(column2 <> "",[column2] = [column2] & " add your extra wording here",[column2])

basically the first comma is your THEN and the 2nd comma is your ELSE.
 

Users who are viewing this thread

Top Bottom