Link to home
Start Free TrialLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Convert Text to Number handling blanks

Hi

In an Access Query I need to convert text to a number - I've been using var([Field1]), but if the field was blank then it returns a zero, is there a way to convert the text to a number & if the field was blank then it remains blank?

Can anyone help?
Avatar of Daniel Pineault
Daniel Pineault

Use IIF() and IsNull(), something along the lines of

IIF(IsNull([Field1]), Null, Val([Field1]))

Open in new window

You can replace Null with whatever is appropriate for your situation.
Avatar of Tom Crowfoot

ASKER

Hi Thanks for that, unfortunately it keeps putting in a zero instead of leaving the result blank
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brilliant, thank you that works well,  but just as a side question & I'll open up a new request - any idea why if I link an excel spreadsheet to the database any query using val it doesn't appear in the list of queries
You can link a worksheet or a range from Excel, not a query.
Ok cool thanks for that, really appreciated
You are welcome!