PC Review


Reply
Thread Tools Rate Thread

Convert text into a number

 
 
=?Utf-8?B?amxhbWJv?=
Guest
Posts: n/a
 
      16th May 2006
I have downloaded data into a system data into a text file. I have imported
this data into access using a link table.

Included in the data from the text file is data in units of measure ie
1,234.567 kg. I have set the data type as text

How do I convert 1,234.567 kg to a numeric (ie 1234.567)
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5kcmV3IFRhcHA=?=
Guest
Posts: n/a
 
      16th May 2006
Val(Replace("1,234.567 kg",",","")) returns 1234.567

Hope this helps.

"jlambo" wrote:

> I have downloaded data into a system data into a text file. I have imported
> this data into access using a link table.
>
> Included in the data from the text file is data in units of measure ie
> 1,234.567 kg. I have set the data type as text
>
> How do I convert 1,234.567 kg to a numeric (ie 1234.567)

 
Reply With Quote
 
Tom Ellison
Guest
Posts: n/a
 
      16th May 2006
Dear JL:

It would work to remove the comma(s) then convert to the numeric type you
desire.

Use Instr() to find the position of commas and concatenate the two parts
before and after the comma. Do this repeatedly till there are no commas
remaining. A function would be a good place to do this.

Tom Ellison


"jlambo" <(E-Mail Removed)> wrote in message
news:0CF72372-F23D-4160-853C-(E-Mail Removed)...
>I have downloaded data into a system data into a text file. I have
>imported
> this data into access using a link table.
>
> Included in the data from the text file is data in units of measure ie
> 1,234.567 kg. I have set the data type as text
>
> How do I convert 1,234.567 kg to a numeric (ie 1234.567)



 
Reply With Quote
 
=?Utf-8?B?amxhbWJv?=
Guest
Posts: n/a
 
      16th May 2006
Thanks for this. I am relatively new to Access, so I probably did not give
all the details. I am trying to set up a query. This data is held in a table
in a column called "Unit of Measure"

What expression would I need to use in the query to convert this text value
into a numeric value

"Andrew Tapp" wrote:

> Val(Replace("1,234.567 kg",",","")) returns 1234.567
>
> Hope this helps.
>
> "jlambo" wrote:
>
> > I have downloaded data into a system data into a text file. I have imported
> > this data into access using a link table.
> >
> > Included in the data from the text file is data in units of measure ie
> > 1,234.567 kg. I have set the data type as text
> >
> > How do I convert 1,234.567 kg to a numeric (ie 1234.567)

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      16th May 2006
You can use the Val function in conjunction with the Replace function. Here
is an example from the Immediate Window:

?Val (Replace("1,234.567 xx",",",""))
1234.567

The Replace function is needed to remove the comma, since the Val function
recognizes only the period (.) as a valid decimal separator.

In a SELECT query, you can use the following in the Field expression:
NumericPart: Val(Replace([TextField],",",""))


where [TextField] is the name of the field that contains your imported text
data. Make the appropriate substitution in the name of the field. You can use
this in the Update To: row of an Update Query:

Val(Replace([TextField],",",""))

Make sure that the numeric field that you are updating is defined as a
Single. If it is the default Long Integer, you will only get the integer
portion (1234) of the string. If the units of measure (Kg, for instance) are
different in various records, then you'll likely want to use a different
update query to update a UnitsOfMeasure field with this information.


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"jlambo" wrote:

> I have downloaded data into a system data into a text file. I have imported
> this data into access using a link table.
>
> Included in the data from the text file is data in units of measure ie
> 1,234.567 kg. I have set the data type as text
>
> How do I convert 1,234.567 kg to a numeric (ie 1234.567)

 
Reply With Quote
 
=?Utf-8?B?amxhbWJv?=
Guest
Posts: n/a
 
      17th May 2006
Thanks for this Tom

I have tried using this in my version of Access 2000, however I get the
following error message

Undefined function 'Replace' in expression

"Tom Wickerath" wrote:

> You can use the Val function in conjunction with the Replace function. Here
> is an example from the Immediate Window:
>
> ?Val (Replace("1,234.567 xx",",",""))
> 1234.567
>
> The Replace function is needed to remove the comma, since the Val function
> recognizes only the period (.) as a valid decimal separator.
>
> In a SELECT query, you can use the following in the Field expression:
> NumericPart: Val(Replace([TextField],",",""))
>
>
> where [TextField] is the name of the field that contains your imported text
> data. Make the appropriate substitution in the name of the field. You can use
> this in the Update To: row of an Update Query:
>
> Val(Replace([TextField],",",""))
>
> Make sure that the numeric field that you are updating is defined as a
> Single. If it is the default Long Integer, you will only get the integer
> portion (1234) of the string. If the units of measure (Kg, for instance) are
> different in various records, then you'll likely want to use a different
> update query to update a UnitsOfMeasure field with this information.
>
>
> Tom Wickerath, Microsoft Access MVP
>
> http://www.access.qbuilt.com/html/ex...tributors.html
> http://www.access.qbuilt.com/html/search.html
> __________________________________________
>
> "jlambo" wrote:
>
> > I have downloaded data into a system data into a text file. I have imported
> > this data into access using a link table.
> >
> > Included in the data from the text file is data in units of measure ie
> > 1,234.567 kg. I have set the data type as text
> >
> > How do I convert 1,234.567 kg to a numeric (ie 1234.567)

 
Reply With Quote
 
Douglas J Steele
Guest
Posts: n/a
 
      17th May 2006
You doing this in a query, or just in VBA?

If it's in a query, it sounds as though you haven't applied all of the
service packs: Office 2000 had this problem when it first came out. The
usual work-around was to develop your own wrapper function for the Replace
function:

Function MyReplace(ToSearch As String, _
FindString As String, _
ReplaceString As String) As String

MyReplace = Replace(ToSearch, FindString, ReplaceString)

End Function

and then use MyReplace instead of Replace.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"jlambo" <(E-Mail Removed)> wrote in message
news:F33122AB-C701-4F2F-98D0-(E-Mail Removed)...
> Thanks for this Tom
>
> I have tried using this in my version of Access 2000, however I get the
> following error message
>
> Undefined function 'Replace' in expression
>
> "Tom Wickerath" wrote:
>
> > You can use the Val function in conjunction with the Replace function.

Here
> > is an example from the Immediate Window:
> >
> > ?Val (Replace("1,234.567 xx",",",""))
> > 1234.567
> >
> > The Replace function is needed to remove the comma, since the Val

function
> > recognizes only the period (.) as a valid decimal separator.
> >
> > In a SELECT query, you can use the following in the Field expression:
> > NumericPart: Val(Replace([TextField],",",""))
> >
> >
> > where [TextField] is the name of the field that contains your imported

text
> > data. Make the appropriate substitution in the name of the field. You

can use
> > this in the Update To: row of an Update Query:
> >
> > Val(Replace([TextField],",",""))
> >
> > Make sure that the numeric field that you are updating is defined as a
> > Single. If it is the default Long Integer, you will only get the integer
> > portion (1234) of the string. If the units of measure (Kg, for instance)

are
> > different in various records, then you'll likely want to use a different
> > update query to update a UnitsOfMeasure field with this information.
> >
> >
> > Tom Wickerath, Microsoft Access MVP
> >
> > http://www.access.qbuilt.com/html/ex...tributors.html
> > http://www.access.qbuilt.com/html/search.html
> > __________________________________________
> >
> > "jlambo" wrote:
> >
> > > I have downloaded data into a system data into a text file. I have

imported
> > > this data into access using a link table.
> > >
> > > Included in the data from the text file is data in units of measure ie
> > > 1,234.567 kg. I have set the data type as text
> > >
> > > How do I convert 1,234.567 kg to a numeric (ie 1234.567)



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text number to number formate thisis_anwar@hotmail.com Microsoft Excel Misc 2 9th Apr 2007 10:48 AM
Convert a number formatted as text to a number in a macro MACRE0 Microsoft Excel Programming 2 22nd Oct 2005 02:51 AM
convert text-format number to number in excel 2000%3f =?Utf-8?B?TGFycnk=?= Microsoft Excel Misc 1 29th Jul 2005 08:18 PM
not able to convert text, or graphic number to regular number in e =?Utf-8?B?a251dHNlbms=?= Microsoft Excel Worksheet Functions 1 2nd Apr 2005 08:41 AM
Convert text number to decimal number Pete Provencher Microsoft Access Queries 4 8th Oct 2003 07:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:19 AM.