Solved

'If then else' in MS Access

Posted on 2010-09-14
5
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33669622
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
ID: 33669676
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
ID: 33669678
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
ID: 33669730
Works perfect - thanks!

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

Thanks again,

Tom
0
 
LVL 19

Expert Comment

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

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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