A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Updating text field to new numeric field & moving minus sign to fr



 
 
Thread Tools Display Modes
  #1  
Old May 19th, 2010, 09:56 PM posted to microsoft.public.access.queries
RyNC
external usenet poster
 
Posts: 11
Default Updating text field to new numeric field & moving minus sign to fr

Hi,

I need some help with the below IF statement for update query. I got it to
move the negative sign to the front of the number, 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


Here is what I have for the update query:

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

Thanks,
RyNC

  #2  
Old May 19th, 2010, 10:42 PM posted to microsoft.public.access.queries
Dorian
external usenet poster
 
Posts: 542
Default Updating text field to new numeric field & moving minus sign to fr

CLng is dropping the fractional part.
Try using CDbl ?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"RyNC" wrote:

Hi,

I need some help with the below IF statement for update query. I got it to
move the negative sign to the front of the number, 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


Here is what I have for the update query:

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

Thanks,
RyNC

  #3  
Old May 20th, 2010, 12:16 AM posted to microsoft.public.access.queries
RyNC
external usenet poster
 
Posts: 11
Default Updating text field to new numeric field & moving minus sign t

That worked, thank you!

"Dorian" wrote:

CLng is dropping the fractional part.
Try using CDbl ?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"RyNC" wrote:

Hi,

I need some help with the below IF statement for update query. I got it to
move the negative sign to the front of the number, 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


Here is what I have for the update query:

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

Thanks,
RyNC

  #4  
Old May 20th, 2010, 01:41 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Updating text field to new numeric field & moving minus signto fr

Just for your future information as long as the field is not null you can use
CDbl.

CDbl("23.32-") returns -23.32

If you want to be careful you can use

UPDATE [MyTable]
SET [MyTable].[MyNumericField] =
IIF(IsNumeric([MyTextField]),CDbl([MyTextField]),Null)

Obviously, if you want zero or some other number result in MyNumericField when
MyTextField cannot be interpreted as a number you can replace null with zero
or -999999 (or whatever value you want).

OR you could use
UPDATE [MyTable]
SET [MyTable].[MyNumericField] = CDbl([MyTextField])
WHERE IsNumeric(MyTextField) = True

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Dorian wrote:
CLng is dropping the fractional part.
Try using CDbl ?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"RyNC" wrote:

Hi,

I need some help with the below IF statement for update query. I got it to
move the negative sign to the front of the number, 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


Here is what I have for the update query:

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

Thanks,
RyNC

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:10 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.