Converting text to numbers and losing all negative values (1 Viewer)

anasttin

New member
Local time
Today, 07:18
Joined
Sep 5, 2016
Messages
5
Hi,

I've set up an access database and in one of the fields in my table the numbers are stored as text and negative numbers have a "-" character preceding them. When I change the field data type from text to numbers in the SQL, I lose the negative values from my output.

ie. in my code below, negative numbers are not being picked up by the select statement - only positive numbers are being captured.

-------------------------------------------------------
SELECT val(nz([db].[value])) as myamount,
from [db]
-------------------------------------------------------

Thanks in advance for any help you can offer.

Kim
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:18
Joined
Feb 19, 2013
Messages
16,605
I can't replicate the problem (i.e. val works for me for negative numbers) so wonder if it is something to do with your data? Or perhaps the code example you provided is not what you are actually using?

You could try specifying a value if null e.g. val(nz(value,0))
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 00:18
Joined
Jan 20, 2009
Messages
12,851
What looks like a negative sign would actually be a dash.

The strings in these expressions use the M-dash Chr(151) and N-dash Chr(150) and return zero when used with Val().
In the Immediate Window:
Code:
? Val("—")
? Val("–")

You can determine which it is by pasting the character between the double quotes.
Code:
? Asc(" ")

Do a Replace with the negative sign character.
 

anasttin

New member
Local time
Today, 07:18
Joined
Sep 5, 2016
Messages
5
Thanks so much Galaxiom... that's awesome and will save me a lot of time.

Much appreciate the help. :)

What looks like a negative sign would actually be a dash.

The strings in these expressions use the M-dash Chr(151) and N-dash Chr(150) and return zero when used with Val().
In the Immediate Window:
Code:
? Val("—")
? Val("–")
You can determine which it is by pasting the character between the double quotes.
Code:
? Asc(" ")
Do a Replace with the negative sign character.
 

Users who are viewing this thread

Top Bottom