#Error in Expression

G

Gsurfdude

Hello,

On an report, I get an "#Error" in the text box control who's Control Source
is set to this expression.
=Sum(IIf([qry_449_Report]![ROUTE_TYPE]=1 And
([qry_449_Report]![DIV_HWY_SURF_TYPE]='G' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='G' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='H' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='H' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='I' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='I'),[qry_449_Report]![SECTION_LENGTH],0))

But, I do not get this error with this one (identical to above except
[qry_449_Report]![DIV_HWY_SURF_TYPE]='I' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='I') is not in the expression E.G.

This works...

=Sum(IIf([qry_449_Report]![ROUTE_TYPE]=1 And
([qry_449_Report]![DIV_HWY_SURF_TYPE]='G' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='G' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='H' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='H'),[qry_449_Report]![SECTION_LENGTH],0))

I am a little stumped why even tho syntax looks OK in the one I get the error
 
A

Allen Browne

Suggestions:

1. You don't need the query name in the expression (unless the field name is
ambiguous.)

2. The IN operator might be easier than repeating the ORs.

Try:
=Sum(IIf([ROUTE_TYPE]=1 AND
([DIV_HWY_SURF_TYPE] IN ('G','H','I') OR
[UDIV_HWY_SURFACE_TYPE] IN ('G','H','I'))
[SECTION_LENGTH], 0))

This assumes that:
a) Route_Type and Section_Length are Number type fields;
b) the DIV... and UDIV fields are Text type.
c) You have text boxes on your report for all 4 fields (even if hidden.)
 
G

Gsurfdude

Worked! Thank you.

Allen Browne said:
Suggestions:

1. You don't need the query name in the expression (unless the field name is
ambiguous.)

2. The IN operator might be easier than repeating the ORs.

Try:
=Sum(IIf([ROUTE_TYPE]=1 AND
([DIV_HWY_SURF_TYPE] IN ('G','H','I') OR
[UDIV_HWY_SURFACE_TYPE] IN ('G','H','I'))
[SECTION_LENGTH], 0))

This assumes that:
a) Route_Type and Section_Length are Number type fields;
b) the DIV... and UDIV fields are Text type.
c) You have text boxes on your report for all 4 fields (even if hidden.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Gsurfdude said:
Hello,

On an report, I get an "#Error" in the text box control who's Control
Source
is set to this expression.
=Sum(IIf([qry_449_Report]![ROUTE_TYPE]=1 And
([qry_449_Report]![DIV_HWY_SURF_TYPE]='G' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='G' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='H' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='H' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='I' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='I'),[qry_449_Report]![SECTION_LENGTH],0))

But, I do not get this error with this one (identical to above except
[qry_449_Report]![DIV_HWY_SURF_TYPE]='I' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='I') is not in the expression
E.G.

This works...

=Sum(IIf([qry_449_Report]![ROUTE_TYPE]=1 And
([qry_449_Report]![DIV_HWY_SURF_TYPE]='G' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='G' Or
[qry_449_Report]![DIV_HWY_SURF_TYPE]='H' Or
[qry_449_Report]![UDIV_HWY_SURFACE_TYPE]='H'),[qry_449_Report]![SECTION_LENGTH],0))

I am a little stumped why even tho syntax looks OK in the one I get the
error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top