Solved

'If then else' in MS Access

Posted on 2010-09-14
5
299 Views
Last Modified: 2013-11-27
Hi,

I have a query in Access (2007) and I want to build an 'If then else' statement. The code below is what I am currently using (without the proposed new statement) but here is the logic that I want it to do:

1) Before the code attached is used I want the statement to check to see if '[AttendanceCalc]![SessionsPossible]' = 0.

2) if '[AttendanceCalc]![SessionsPossible]' does = 0 then return 0 in the query results (currently it return '#error').

3) else do the calculation attached.

Can anyone help with this please?

Thanks,

Tom
%Att: Round(([AttendanceCalc]![SessionsAttended]/[AttendanceCalc]![SessionsPossible])*100,0)

Open in new window

0
Comment
Question by:optimumreports
  • 2
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
this should do:
  	



%Att: IF([AttendanceCalc]![SessionsPossible] = 0; 0; Round(([AttendanceCalc]![SessionsAttended]/[AttendanceCalc]![SessionsPossible])*100,0))

Open in new window

0
 
LVL 1

Author Comment

by:optimumreports
Comment Utility
Hi,

Thanks for the pronpt relpy. I get the following error when I tried the code:

"The expression you entered contains invalid syntax.

You omitted an operand or operator, you entered an invalid character or comma, or you entered text without surrounding in quotation marks".

I will try and fix this but - do you have know where the problem is straight away that would be great.

Thanks,

Tom
0
 
LVL 19

Accepted Solution

by:
MINDSUPERB earned 500 total points
Comment Utility
Tom,

%Att: IIF([AttendanceCalc]![SessionsPossible] = 0; 0; Round(([AttendanceCalc]![SessionsAttended]/[AttendanceCalc]![SessionsPossible])*100,0))

Just a thought of using IIF than IF.

Ed
0
 
LVL 1

Author Closing Comment

by:optimumreports
Comment Utility
Works perfect - thanks!

For future reference - what is the difference between 'IF' and 'IFF'?

Thanks again,

Tom
0
 
LVL 19

Expert Comment

by:MINDSUPERB
Comment Utility
As what I know, IF is used in Excel and IIF is in Access.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now