Results 1 to 6 of 6
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Currency appears as text in vba debug


    Hello everyone!

    The last line results in false when I type
    Code:
    ?balleft >=baldue
    in the immediate window. And it should not! Debug.print shows the balleft IS greater than the baldue. When I hover over baldue I get: "$164.69" WITH the quotes. Balleft is fine 400. What am I missing please? TIA!

    Code:
        Dim strsql As String
        Dim baldue As Currency
        Dim balleft As Currency
        Dim payment As Currency
        Dim CRAmount As Currency
        Dim DBAmount As Currency
    
        baldue = Format(Me.baldue,"currency")
        balleft = Me.payment
    
        ' Add to payments
         DoCmd.RunSQL "INSERTINTO AsmtPayments ( PaymentAmount, MemberID, PaymentDate ) " & vbCrLf& _
        "SELECT[Forms]![AccountsandPayments]![Accountssubform].[Form]![payment] AS Expr1,Accounts.MemberID,    
        [Forms]![AccountsandPayments]![Accountssubform].[Form]![datepaid]AS Expr2 " & vbCrLf & _
        "FROM Accounts "& vbCrLf & _
        "WHERE(((Accounts.MemberID)=[Forms]![AccountsandPayments]![MemberID]));"
    
        DoCmd.SetWarnings True
        'Me.Requery
    
         'There is money and assessments to pay
        ' Find first unpaid item
       Forms![AccountsandPayments]![Accountssubform].SetFocus
       Forms![AccountsandPayments]![Accountssubform].Form![DateAssessed].SetFocus
        DoCmd.GoToRecord , , acFirst
    
        While balleft >=baldue Andbaldue > 0

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The FORMAT function returns a text value, not a numeric one.
    I don't think you need to use it all here (especially since you already declaring the variable to be currency!).

    Change this row:
    Code:
        baldue = Format(Me.baldue,"currency")
    to this:
    Code:
        baldue = Me.baldue

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Format() function returns a string value, not numeric. However, I am not getting the behavior you describe. I hover over baldue and there are no quote marks nor dollar sign. My test code:
    Code:
    Sub test2()
    Dim baldue As Currency, balleft As Currency
    baldue = Format(164.69, "Currency")
    balleft = 400
    Debug.Print balleft >= baldue
    End Sub
    Why use Format() function?

    Missing a space in Andbaldue - is that just a typo in post?
    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.

  4. #4
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thank you June and Joe. Yes it was a typo in my post. I added the extra "format" to try and combat the problem, obviously didn't work. I've removed the line and still get the string value.
    Click image for larger version. 

Name:	screenshotbaldue.png 
Views:	9 
Size:	101.2 KB 
ID:	33336

  5. #5
    Join Date
    Apr 2017
    Posts
    1,776
    Is the reference Me.baldue to table field or to form control? Have you same name for field and control? What is format of field? What is format of control?

  6. #6
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Hi ArviLaanemets! It refers to an unbound, calculated form control....aaaand....you nailed it. I had "format" on that control too! Removed it and all is well.

    Thank you everyone for your input!

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

Similar Threads

  1. Replies: 1
    Last Post: 10-03-2017, 02:16 AM
  2. Using Currency in text string.
    By Homegrownandy in forum Queries
    Replies: 4
    Last Post: 05-12-2017, 07:22 AM
  3. Replies: 2
    Last Post: 04-17-2017, 10:19 AM
  4. Currency formatted Text Box Question
    By data808 in forum Access
    Replies: 4
    Last Post: 05-09-2014, 12:50 PM
  5. Currency/text display issues
    By Akazuba in forum Access
    Replies: 3
    Last Post: 04-20-2011, 07:51 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