Results 1 to 5 of 5
  1. #1
    azurekca is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3

    Why does this query change my numeric data to text

    I'm running a make table query that is converting my numeric data into text and I need it to remain numeric. The two input numeric fields are set to Number/Double.



    USE_Number: Switch(Not IsNull([NumericField1]),[NumericField1]*0.1,Not IsNull([NumericField2]),[NumericField2]*0.001)

    This is giving me the correct results, Nulls where neither number is available, and the correct math where the number is available, but unfortunately results in a text field.

    I tried adding CDbl, and this results in a numeric field but where neither Number is available the result is #ERROR and I need it to be Null

    USE_Number: Round(CDbl(Switch(Not IsNull([NumericField1]),[NumericField1]*0.1,Not IsNull([NumericField2]),[NumericField2]*0.001)),2)

    Any help on this would be really appreciated! Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    CDbl and other conversion functions cannot handle Null. Will have to return a value such as 0 in place of the Null. Use Nz() 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
    azurekca is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3
    Thank you, I realized that. As I don't want zeros in my resulting table, I was hoping to find another solution.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe build a query that does that calc then use that query as the source for MAKE TABLE. Use this expression for the Update To parameter:

    IIf([USE_Number]=0, Null, [USE_Number])

    Or could then run an UPDATE sql and change all the zeros to Null.

    Why do you need to run MAKE TABLE?
    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.

  5. #5
    azurekca is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3
    Thank you June7, I tried a modified version of your suggestion and it's working now!

    I used: IIf(IsNull([NumericField1]) AND IsNull([NumericField2]), Null, Round(CDbl(Switch(Not IsNull([NumericField1]),[NumericField1]*0.1,Not IsNull([NumericField2]),[NumericField2]*0.001)),2))

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

Similar Threads

  1. Replies: 19
    Last Post: 03-29-2014, 12:48 AM
  2. Convert text to numeric value
    By Natella in forum Programming
    Replies: 4
    Last Post: 11-11-2013, 02:55 PM
  3. Change Text Box Data Source On Open Event
    By mcktigger in forum Programming
    Replies: 1
    Last Post: 01-18-2013, 12:24 PM
  4. Numeric vs. Text
    By Niki in forum Access
    Replies: 4
    Last Post: 06-10-2011, 01:28 AM
  5. Split Numeric Data out of Irregular Text Field
    By nathanielban in forum Queries
    Replies: 6
    Last Post: 12-21-2010, 10:30 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