Importing *.txt file containing negative numbers

A

Alojz

Hello,
I import *.txt file where there are negative values in source data. The
problem is, that negative value in source list is written as following:
12.457.965,60-
e.g. with minus sign behind the number.
What shall I do to have this record recognized as negative number in Access
? So far, I get error message that this particular item (all negatives) are
not imported. Is there special format for negative numbers I can use to
easily import negatives numbers with minus sign behind?
 
D

Douglas J. Steele

You could try importing the values as text fields, not numbers.

Once you've done that, add a new numeric field to the table, and set its
value using something like:

UPDATE MyTable
SET MyNumericField = IIf(Right([MyTextField], 1) =
"-", -CLng(Left([MyTextField], Len([MyTextField]) - 1), CLng([MyTextField])
 
A

Alojz

Hi,
thx for posting, I did something similar in the meantime, had problems with
thousand separators when text not value, so needed to replace "." with "".
Will check ur code asap and will let u know how it works.

Douglas J. Steele said:
You could try importing the values as text fields, not numbers.

Once you've done that, add a new numeric field to the table, and set its
value using something like:

UPDATE MyTable
SET MyNumericField = IIf(Right([MyTextField], 1) =
"-", -CLng(Left([MyTextField], Len([MyTextField]) - 1), CLng([MyTextField])

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Alojz said:
Hello,
I import *.txt file where there are negative values in source data. The
problem is, that negative value in source list is written as following:
12.457.965,60-
e.g. with minus sign behind the number.
What shall I do to have this record recognized as negative number in
Access
? So far, I get error message that this particular item (all negatives)
are
not imported. Is there special format for negative numbers I can use to
easily import negatives numbers with minus sign behind?
 
A

Alojz

sorted out, thx for help

Douglas J. Steele said:
You could try importing the values as text fields, not numbers.

Once you've done that, add a new numeric field to the table, and set its
value using something like:

UPDATE MyTable
SET MyNumericField = IIf(Right([MyTextField], 1) =
"-", -CLng(Left([MyTextField], Len([MyTextField]) - 1), CLng([MyTextField])

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Alojz said:
Hello,
I import *.txt file where there are negative values in source data. The
problem is, that negative value in source list is written as following:
12.457.965,60-
e.g. with minus sign behind the number.
What shall I do to have this record recognized as negative number in
Access
? So far, I get error message that this particular item (all negatives)
are
not imported. Is there special format for negative numbers I can use to
easily import negatives numbers with minus sign behind?
 
R

RyNC

Hi Douglas,

This code is almost working for me. I got it to move the negative sign to
the front, but now it is removing all numbers after my decimal point. I've
checked to make sure my formatting for [MyNumericField] is double and 2
decimal points.

For example:

[MyTextField] is 23.32-

I run update query and....

[MyNumericField] is -23


Also, I had to modify your code because there were paranthesis missing.
Here is what I have:

IIf(Right([MyNumericField],1)="-",-CLng(Left([MyTextField],Len([MyTextField])-1)),CLng([MyTextField]))

Douglas J. Steele said:
You could try importing the values as text fields, not numbers.

Once you've done that, add a new numeric field to the table, and set its
value using something like:

UPDATE MyTable
SET MyNumericField = IIf(Right([MyTextField], 1) =
"-", -CLng(Left([MyTextField], Len([MyTextField]) - 1), CLng([MyTextField])

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Alojz said:
Hello,
I import *.txt file where there are negative values in source data. The
problem is, that negative value in source list is written as following:
12.457.965,60-
e.g. with minus sign behind the number.
What shall I do to have this record recognized as negative number in
Access
? So far, I get error message that this particular item (all negatives)
are
not imported. Is there special format for negative numbers I can use to
easily import negatives numbers with minus sign behind?
 

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