Avatar of optimumreports
optimumreports
 asked on

'If then else' in MS Access

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

Microsoft AccessSQL

Avatar of undefined
Last Comment
MINDSUPERB

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

this should do:
  	

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

Open in new window

optimumreports

ASKER
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
ASKER CERTIFIED SOLUTION
MINDSUPERB

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
optimumreports

ASKER
Works perfect - thanks!

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

Thanks again,

Tom
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
MINDSUPERB

As what I know, IF is used in Excel and IIF is in Access.