Using MS Access/Report If Then Statement

Advertisement


Question
QUESTION: I am trying to write a if statement on a report field that is sourced by a query.  I am trying to say if the Transaction Type field = Intercompany give me All FS Item #s fro the FS Item field on the query that are between 0000010000 and 0000059999, otherwise give me all the FS Item numbers from the FS item number field in the query.

=IIf([Transaction Type]="Intercompany",[FS Item] Between "0000010000" And "0000059999",[FS Item])

ANSWER: I would do it differently. I would add a field that returned True or False as to whether the FS Item was in the range. Then I would set the criteria to:

Transaction Type = "Intercompany" AND Betw = True OR Transaction Type <> "Intercompany"

Hope this helps,
Scott<>

---------- FOLLOW-UP ----------

QUESTION: Scott,

Not sure I understand you answer completely?  Create a new field in my query first for the True of False, and then in the report type this criteria?  How will this bring me back the "FS Item" field number?

Answer
Queries do not have fields. They have columns that are either linked to a field or contain an expression.

But yes you create the column in your query. You can set the criteria in the query or as part of the OpenReport method.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.