Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    FormatCurrency not returning formatted amount as expected?


    tempCredit is Dim'd as Currency
    Code:
                    tempCredit = FormatCurrency(Me.tbNewCredit.Value)
                    MsgBox "Credit amount, " & tempCredit & ", exceeds current balance in account."
    When 5000 is entered into text box tbNewCredit, I'm expecting the FormatCurrency function to return $5,000. I still get 5000. What am I missing here?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    sounds like formatcurrency is a udf - so the problem may be there

    or perhaps tempcredit is the wrong datatype - what does does formatcurrncy function return? string? number?

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What do you get with Msgbox "Temp Credit is : " & tempCredit

    Perhaps you need Format (tempCredit, "Currency")??

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    tempCredit had to be Dim'd string NOT currency

    Code:
                    tempCredit = FormatCurrency(Me.tbNewCredit)
                    MsgBox "Credit amount, " & tempCredit & ", exceeds current balance in account."

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As Ajax suggested, FormatCurrency() is apparently a User-Defined Function, and I'm guessing that it uses Access' native Format() function.

    And, FYI, the reason that tempCredit had to be dimmed as a String, is that Format() always returns a String, regardless of the DataType of the data being formatted!

    If you then need to use the formatted data as it was originally meant to be used, you can wrap it in the appropriate Type Conversion Function, such as CDbl(), CDate() or, in this case, as CCur().

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Quote Originally Posted by Missinglinq View Post
    As Ajax suggested, FormatCurrency() is apparently a User-Defined Function

    Linq ;0)>
    No. "FormatCurrency" is a native function in A2003, not user defined. However, its HELP text said nothing about the return attributes of the function. Anyway, after looking at the "Format" function, I concluded that "tempCredit" needed to be Dim'd string as would be required with "Format".

    Bill

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Amazing! In fifteen years of working with Access, and 10 years trolling this and half-a-dozen other Access forums, I've never run into FormatCurrency! OF course, that's why I find Access to be so interesting...if you use it much you're always learning something new!

    My guess would be that it uses the same low level code as the Format() function, and since it allows such things as adding Parens around negative numbers, it obviously has to return a String.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The currency data type should be able to accept a numeric value and or a properly formatted string. I do not remember Access 2003 being any different, but I suppose it might be.

    Code:
    Dim curSum As Currency
    curSum = 5.5
    
    Debug.Print curSum
    Debug.Print FormatCurrency(900.2, 2, vbTrue, vbTrue)
    
    curSum = FormatCurrency(900.2, 2, vbTrue, vbTrue)
    
    Debug.Print curSum

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

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

Similar Threads

  1. Calling function not returning as expected...
    By sstiebinger in forum Programming
    Replies: 19
    Last Post: 08-18-2015, 02:26 PM
  2. Replies: 12
    Last Post: 07-18-2014, 01:22 PM
  3. Query not returning expected results
    By MarcieFess in forum Queries
    Replies: 3
    Last Post: 10-18-2013, 05:28 PM
  4. Replies: 3
    Last Post: 07-23-2013, 01:30 PM
  5. Query not returning all expected results
    By amenitytrust in forum Queries
    Replies: 6
    Last Post: 11-05-2012, 07:13 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