Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    Sep 2021
    Posts
    13

    Text To Numbers in Query


    Hello, I tried to find a topic on my question but couldn't find one so hopefully I don't bug anyone to ask my question here. I'm trying to create a field in my query to change text to numbers. I did a google search and found a function that I thought would work, but it doesn't do anything when I run the query. The function I used is "numbertext:Cstr([fieldname])". Can someone point me to a topic on my question or help me out as to what the function is to write text to numbers? I apologize if I somehow missed an existing topic on this question.

    Thanks in advance.

    Joel

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,921
    That converts a number to a string?

    Look at the Val() function.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    CStr is short for (C)onvert(Str)ing or convert to string.

    You also have CInt, CDbl, CLng, CCur, etc that convert an input to integer, double, long, currency respectively. There are more than I've listed here, but each of these are examples of a number data type. If you don't already know do a quick Google search for ms access datatypes to find a table of numeric datatypes to find out which is appropriate for you.

    [edit] Resources:
    https://docs.microsoft.com/en-us/off...sion-functions
    https://support.microsoft.com/en-us/...9-3418f622e482

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,653
    All cstr() does is convert a value to a text datatype. https://www.techonthenet.com/access/...atype/cstr.php

    Most of the functions I have seen usually convert currency datatype to words.
    Here's one - https://support.microsoft.com/en-us/...8-69442cd55d98

    Just to be clear, you want to change "Four" to 4, or "TwentySeven" to 27?

    Whats the upper end of the numbers you need?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Sep 2021
    Posts
    13

    Number to Text Function in Query

    Hello, I'm trying to find any threads that talk about converting numbers to text in a query. I search for threads on this topic but I can't seem to find one that tells me what function to use. Can someone point me to a topic that says specifically what function to use, or help me out? Thanks,


    Joel Wiggers

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,921
    First it is Text to Numbers, now numbers to text?
    Which is it?

    There is no miracle function to do that. You need to find one that has already been written?
    Here is one/two depending on how you look at it?
    https://www.access-programmers.co.uk.../#post-1785770
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    Either way, isn't this just about built in conversion functions?
    CLng("123") becomes 123 (long number type)
    Cstr(123) becomes "123" string

    and so on...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,921
    Quote Originally Posted by Micron View Post
    Either way, isn't this just about built in conversion functions?
    CLng("123") becomes 123 (long number type)
    Cstr(123) becomes "123" string

    and so on...
    Honestly not sure. In the text to numbers post I offered Val(), but I have simply concatenated numbers to strings in the past, without having to convert to a string.?
    Someone thought it might be actual numbers in words, hence my link.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,418
    you can just use

    txtStr="" & number

  10. #10
    Join Date
    Sep 2021
    Posts
    13

    Number To Words

    Quote Originally Posted by wheatlandacctech View Post
    Hello, I'm trying to find any threads that talk about converting numbers to text in a query. I search for threads on this topic but I can't seem to find one that tells me what function to use. Can someone point me to a topic that says specifically what function to use, or help me out? Thanks,

    Joel Wiggers
    I copied the code from the link you sent me and then called it in the Form_Current event but it didn't work. It threw and error exception that says "Argument Not Optional". What did I do wrong?

    Joel Wiggers

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,921
    You need to pass the number value to the function?

    That is what functions do generally. They take parameters passed in and return a value using those parameters.

    Code:
    strNumberInWords = English(2345.75)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I merged your duplicate threads since both had replies.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    WGM,

    Val("123 Dog") = 123
    Val("Dog 123") = 0

    Val stops at the 1st character than cannot be recognized as a number. Examples are needed and until then, I'm going to bow out. Who knows, this could be about converting data types or it could mean converting "Four" to 4 or vice versa, as has been suggested.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Join Date
    Sep 2021
    Posts
    13
    So I tried to pass a number to the function from a textbox on my form and I get this error. "Compile Error" "Function call on left-hand-side of assignment must return Variant or object"

    I'm still doing something wrong.

    Joel Wiggers

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,418
    maybe, maybe not - would help if you showed the function code you are actually using and how you are using it - together with some example data of what you are inputting and what result you expect

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-11-2020, 08:18 PM
  2. UPDATE QUERY to Separate Numbers from Text in a Text Field
    By pjordan@drcog.org in forum Queries
    Replies: 2
    Last Post: 05-29-2015, 02:44 PM
  3. Replacing numbers with text at the query level
    By lonesoac0 in forum Queries
    Replies: 4
    Last Post: 09-03-2014, 03:16 PM
  4. Replies: 3
    Last Post: 06-12-2014, 10:30 AM
  5. Replies: 3
    Last Post: 09-05-2012, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums