Rookie Question

  • Thread starter Thread starter SteveB
  • Start date Start date
S

SteveB

How do I add a field to a query and how can I insert an if statement that
would be something like this:

IF Field1="K" , (True) =1, (False) =0

Thanks for your help.
 
SteveB said:
How do I add a field to a query and how can I insert an if statement that
would be something like this:

IF Field1="K" , (True) =1, (False) =0

Thanks for your help.

Make calculated field with this record source:

=IIf([Field1]="K", 1, 0)

Tom Lake
 
Tom said:
SteveB said:
How do I add a field to a query and how can I insert an if statement that
would be something like this:

IF Field1="K" , (True) =1, (False) =0

Thanks for your help.

Make calculated field with this record source:

=IIf([Field1]="K", 1, 0)

Tom Lake

A couple of things I'd add:

1) A great way of finding out about these functions and how to use them
is to get familiar with the "Expression Builder" (Google for loads of
references, including videos). It helps you get the syntax right, both
of the functions and of the various bits and bobs of your database (e.g.
a control on a subform somewhere). One tip: if you click on a function
it often comes up with "<<Expr>>" - this denotes something you have to
replace: it's a common stumble to leave these placeholders in situ
(which throws up errors).

2) Just comparing the field to a constant might not be enough. You may
need to use other Text functions to make sure you TRIM off any spaces,
or pick only the LEFT-most character - unless you can be certain that
every record (present and future) will contain only one character in
this field.

Phil, London
 
How do I add a field to a query and how can I insert an if statement that
would be something like this:

IF Field1="K" , (True) =1, (False) =0

Thanks for your help.

In Access, True is -1, not 1, so if you mean to give it a True value,
Add a new column to the query grid.

NewField:IIf([Field1]= "K",-1,0)
 
How do I add a field to a query and how can I insert an if statement that
would be something like this:

IF Field1="K" , (True) =1, (False) =0

Thanks for your help.

You don't actually need an IIF statement at all. Since a logical expression is
either TRUE or FALSE, you can just use a calculated field

IsItK: [Field1] = "K"

A form control bound to this calclated field will display True (checked, -1,
Yes, ...) or False (unchecked, 0, No, ...) as appropriate.
 
Back
Top