Possible bug using Clng or iif function

  • Thread starter Thread starter roy fisher
  • Start date Start date
R

roy fisher

I've linked in a table (in A97) into a 2K Access database.
This table contains a text field that I need as a long.

Simple enough, I thought, and created an expression in a
query using clng. First problem was that some records were
blank in that field so I got errors. I then changed the
expression to
iif(isnull([op number]),0,clng([op number])

and this seemed to work just fine with the values aligned
to the right hand side of the cell as numeric values do.

The trouble is that when I put in an expression in the
criteria cell such as >10 or even 10 and run the query I
get the values displayed correctly for a second or two
until it errors out with the message
Data Type mismatch in criteria expression

This can't be the case as the query builder accepts the
values as a long in the SQL WHERE but doesn't when the
query runs.

I've had a look on the web but haven't found any help as
yet. One thing my Access is on SR-1 but as I have to rely
on an IT dept to upgrade to SR-2 I need to convince them
first. Can anyone help?

Thanks

Roy Fisher
 
my guess is that you have an entry that contains an empty string "",
which clng will not convert either.

TRY: iif(LEN(TRIM([op number]) & "") = 0, 0, clng([op number]))

--
HTH

Dale Fye


I've linked in a table (in A97) into a 2K Access database.
This table contains a text field that I need as a long.

Simple enough, I thought, and created an expression in a
query using clng. First problem was that some records were
blank in that field so I got errors. I then changed the
expression to
iif(isnull([op number]),0,clng([op number])

and this seemed to work just fine with the values aligned
to the right hand side of the cell as numeric values do.

The trouble is that when I put in an expression in the
criteria cell such as >10 or even 10 and run the query I
get the values displayed correctly for a second or two
until it errors out with the message
Data Type mismatch in criteria expression

This can't be the case as the query builder accepts the
values as a long in the SQL WHERE but doesn't when the
query runs.

I've had a look on the web but haven't found any help as
yet. One thing my Access is on SR-1 but as I have to rely
on an IT dept to upgrade to SR-2 I need to convince them
first. Can anyone help?

Thanks

Roy Fisher
 
You might also try using the IsNumeric function. That will handle nulls, empty
strings, and strings with non-numeric characters (for instance, where someone
typed an OH vice a ZERO).

IIF(IsNumeric([opNumber]),Clng(OpNumber),0)
 
Hi,
I am facing the problem as mentioned above. Scenario is that
i am using IIF in Query

Select Query1.Code, Query1.Val1, Query2.Val1, IIF(ISNULL(Query1.Val1),Query2.Val1,Query1.Val1) as Val1
FROM Query2

Values are like:
-------------------------------------------------------------------------------------------------------------------------------------------------
Query1.Code - Query1.Val1 - Query2.Val1 - IIF(ISNULL(Query1.Val1),Query2.Val1,Query1.Val1) as Val1
-------------------------------------------------------------------------------------------------------------------------------------------------001 - 1 - -
002 - 2 -
003 - 3 - 3 -
-------------------------------------------------------------------------------------------------------------------------------------------------
no value returned by expression IIF

I'll appreciate if any one help me
THANKS
SMAZ
 

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

Similar Threads


Back
Top