Results 1 to 4 of 4
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    MS Access VBA - Retrieve DAO.Field.Value as verbatim string

    Hi,



    Before I write a function to do this, I figured I would consult here because it seems like a rather silly thing....

    I am looking to get the "verbatim" value of a field.

    For example, If the field's value is $100.00 then getting field.value in VBA returns "100"
    Even more strange is that if the field's value is $100.50 then getting field.value returns "100.50" (it now treats it as a double?)

    My desire is when the fields value is $100.00 then i can retrieve a string that is "$100.00" - currency sign and its level of precision.

    This would be my desire for not just currency types but all (most) types.

    MS Documentation points out.... https://docs.microsoft.com/en-us/off...e-property-dao
    The setting or return value is a Variant data type that evaluates to a value appropriate for the data type, as specified by the Type property of an object.
    The reason I need this is because List Boxes don't support individual formatting of rows (lame) - when the listbox rowsource is set to "Value List"... When set to RowSource, the listbox will
    inherit the rowsource field data type and present them in the listbox as such. Unfortunately, my listbox must remain as a Value List rowsource type for this application.

    Any ideas besides writing a custom function?

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If listbox is set for Value List then how is the items list created?

    Maybe you want to use Format() function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    by 'verbatim' I presume you mean the underlying value - so the underlying value for $100.00 is actually 100, for $100.50 is 100.5 - what you are seeing is a formatted view of the data. Yes/No fields are stored as -1 and 0, dates are also stored as a number (today is 43775).

    Value lists are by their nature strings, so you cannot turn it into a variant

    Your requirement is not too clear - do you mean a single list

    100
    $100
    $100.50

    or do you mean a list for 100, another for $100 and a third for $100.50?


    In any event your link refers to the referenced value of a field - a field can be one of many datatypes, but all returned through one variable and it is that variable which is a variant.

    So you can use the type property to determine whether the value is an integer, long, double, currency, date, string etc and then as June suggests, use the appropriate format parameter to display the data as required.

    you can convert a number to a string just by adding a quote

    myNum=100
    myString="" & myNum=100
    myNum=100.5
    myString="" & myNum=100.5

    however that will ignore currency

    myNum=$100
    myString="" & myNum=100
    myNum=$100.5
    myString="" & myNum=100.5

    EDIT: this is what happens when you append a field to your valuelist anyway

  4. #4
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Maybe you want to use Format() function.
    June7,
    Format function will format the data into string perhaps, but this assumes you know the field's datatype to begin with.
    You will have to accept that I can only use Value List in this instance.



    Your requirement is not too clear - do you mean a single list
    Ajax,
    Your reply is all over the place. i don't think i could've been more clear.
    I need the "verbatim" value, which is poor terminology indicating I need the field's FORMATTED value as a string.

    So, it appears a custom function to do this "conversion" is necessary.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-06-2016, 12:47 PM
  2. Replies: 3
    Last Post: 05-26-2013, 08:57 AM
  3. how to retrieve a value from a field by index?
    By RedGoneWILD in forum Programming
    Replies: 6
    Last Post: 07-14-2012, 04:48 PM
  4. Replies: 0
    Last Post: 04-14-2012, 07:36 PM
  5. Use DLookup to Retrieve Field Value from a Date?
    By Heatshiver in forum Programming
    Replies: 8
    Last Post: 04-06-2012, 10:09 AM

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