avoid #error

G

geebee

hi,

i have a query which contains a field to convert text to number:
CLng(Mid([fieldname]], 1, 8))

However, I am getting an #error for some of the rows in the query because
either the fieldname contains something like 'Led24 or doesnt contain a value
at all. how can i amend to solve this?


thanks in advance,
geebee
 
J

John Spencer

I would try

IIF(IsNumeric(Mid([fieldname],1,8)),CLng(Mid([fieldname],1,8)),Null)

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
A

Allen Browne

geebee said:
i have a query which contains a field to convert text to number:
CLng(Mid([fieldname]], 1, 8))

However, I am getting an #error for some of the rows in the query
because either the fieldname contains something like 'Led24 or
doesnt contain a value at all. how can i amend to solve this?

CLng() cannot handle Nulls, so try an expression like this:
IIf([fieldname] Is Null, Null, Val(Left([fieldname], 8)))

That returns a Double; if you need a Long Integer:
IIf([fieldname] Is Null, Null, CLng(Val(Left([fieldname], 8))))
 

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