Computing.Net > Forums > Database > If statements and numbers

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

If statements and numbers

Reply to Message Icon

Name: BarbBatesKelleher
Date: May 5, 2009 at 08:44:00 Pacific
OS: Windows XP
Product: Microsoft / Access 2003
Subcategory: General
Comment:

I'm creating an honor roll for my grades table. When I try to run an average on the output from this statement it gives me a data type mismatch. I'm assuming that the output is seen as text even though I have formatted it in the query as a number. Is there any way to make sure this is output as a number. The statement is: GradeNum: IIf([Grade]="A+",99,IIf([Grade]="A",95,IIf([Grade]="A-",91,IIf([Grade]="B+",88,IIf([Grade]="B",85,IIf([Grade]="B-",82,IIf([Grade]="C+",78,IIf([Grade]="C",75,IIf([Grade]="C-",72,IIf([Grade]="D",65,IIf([Grade]="F",0,"?")))))))))))
Thank you.



Sponsored Link
Ads by Google

Response Number 1
Name: orange
Date: May 6, 2009 at 07:51:21 Pacific
Reply:

I set up a small table and used your iif. I also did an AVG using the Totals icon on query design screen. I got a numeric result without error.

Here is the underlying SQL.

SELECT Avg(IIf([Grade]="A+",99,IIf([Grade]="A",95
,IIf([Grade]="A-",91,IIf([Grade]="B+",88
,IIf([Grade]="B",85,IIf([Grade]="B-",82
,IIf([Grade]="C+",78,IIf([Grade]="C",75
,IIf([Grade]="C-",72,IIf([Grade]="D",65
,IIf([Grade]="F",0,"?")))))))))))) AS GradeNum
FROM Grades;


0

Response Number 2
Name: BarbBatesKelleher
Date: May 6, 2009 at 08:16:07 Pacific
Reply:

Thanks. I've tried this and also setting each number with the Int(99) and Fix(99) (integer and fixed number format) and I always get the "type mismatch" error in both a second query or report. Something else must be going on behind the scene that I can't see. I exported it to Excel and was able to do the math there so I no longer think it is exporting as text. I have never seen anything like this in Access before.


0

Response Number 3
Name: orange
Date: May 7, 2009 at 06:39:25 Pacific
Reply:

Are you saying that the query I listed gives Type Mismatch?
I'm running Access 2003 on Win XP SP3 with no error.

If you're running more queries, it could be something in some other query or calculation.


0

Response Number 4
Name: orange
Date: May 7, 2009 at 07:32:05 Pacific
Reply:

Are you saying that the query I listed gives Type Mismatch?
I'm running Access 2003 on Win XP SP3 with no error.

If you're running more queries, it could be something in some other query or calculation.


0

Response Number 5
Name: BarbBatesKelleher
Date: May 7, 2009 at 09:47:16 Pacific
Reply:

Thanks. I run the query without the AVG because I am extracting other data for the report. I add the =avg({GradeNum]) as a new field in a report generated by the query. This is where I get the "type mismatch" and the report won't run. If I try to base a second query on the first the same thing happens when I try to apply =avg or =sum to the field [GradeNum]. It's quite strange. It's acting like it is a text field when in fact it exports to Excel as a number. I've never seen anything like this.

Update: I created this query and report based on the same table on another computer running Access 2003 instead of 2002 and it worked beautifully.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: If statements and numbers

if statement help pls www.computing.net/answers/dbase/if-statement-help-pls/407.html

word if statement, please help www.computing.net/answers/dbase/word-if-statement-please-help/359.html

Taking out The, A, and An in sortin www.computing.net/answers/dbase/taking-out-the-a-and-an-in-sortin/57.html