Solved

format Currency on Variable for Message box

Posted on 2014-03-05
6
517 Views
Last Modified: 2014-03-06
what is the proper syntax to display the value in a MsgBox as currency ( $10,000.00)  As you can see I have tried 2 different methods, neither successful.

Private Sub NetAmount_AfterUpdate()
   On Error GoTo NetAmount_AfterUpdate_Error

Dim nAmt As Long
Dim nAmtTotal As Long

nAmt = Format(Me.NetAmount, "Currency")
nAmtTotal = FormatCurrency(Forms![frmCodingSlip]![txtMCFRemainingUS].value, 2)
    If nAmt > nAmtTotal Then
        Select Case _
            MsgBox("The system is unable to process the current invoice due to the Remaining Funds of " _
            & nAmtTotal & " is less than the amount of entered." _
            & vbCrLf & "" _
            & vbCrLf & "Please validate and adjust the amount enter that is no greater than the Remaining Funds." _
            , vbOK Or vbCritical Or vbDefaultButton1, "Funds Discrepancy")
        
            Case vbOK
                Me.NetAmount = vbNullString
                Exit Sub
        End Select
    Else
        Me.Currency.SetFocus
        Me.Currency.Dropdown
    End If
   On Error GoTo 0
   Exit Sub

NetAmount_AfterUpdate_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure NetAmount_AfterUpdate of VBA Document Form_frmInvoiceSub"
End Sub

Open in new window

0
Comment
Question by:Karen Schaefer
6 Comments
 
LVL 2

Expert Comment

by:gdarcan
ID: 39907812
You may use FormatNumber function. Please refer to w3schools
0
 

Author Comment

by:Karen Schaefer
ID: 39907885
sorry that does not get me currency ($10,000.00)
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39907993
When you Format() a numeric value you make it a string so $10,000 would be less than $2.  Do the compare using the unformatted fields.  Then format for display.  Formatting is for humans, not computers.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39908566
Yes, you have got this wrong. Here is how (air code):
Private Sub NetAmount_AfterUpdate()
   On Error GoTo NetAmount_AfterUpdate_Error

Dim nAmt As Currency
Dim nAmtTotal As Currency

If IsNull(Me!NetAmount) Then Exit Sub

nAmt = CCur(Me!NetAmount)
nAmtTotal = CCur(Format(Forms![frmCodingSlip]![txtMCFRemainingUS].Value, "0.00"))
    If nAmt > nAmtTotal Then
        Select Case _
            MsgBox("The system is unable to process the current invoice due to the Remaining Funds of " _
            & Format(nAmtTotal, "Currency") & " is less than the amount of entered." _
            & vbCrLf & "" _
            & vbCrLf & "Please validate and adjust the amount enter that is no greater than the Remaining Funds." _
            , vbOK Or vbCritical Or vbDefaultButton1, "Funds Discrepancy")
        
            Case vbOK
                Me!NetAmount = Null
                Exit Sub
        End Select
    Else
        Me!Currency.SetFocus
        Me!Currency.Dropdown
    End If
    On Error GoTo 0
    Exit Sub

NetAmount_AfterUpdate_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure NetAmount_AfterUpdate of VBA Document Form_frmInvoiceSub"
End Sub

Open in new window

/gustav
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39910023
Select Case _
            MsgBox("The system is unable to process the current invoice due to the Remaining Funds of " _
            & Format(nAmtTotal, "Currency") & " is less than the amount of entered." _
            & vbCrLf & "" _
            & vbCrLf & "Please validate and adjust the amount enter that is no greater than the Remaining Funds." _
            , vbOK Or vbCritical Or vbDefaultButton1, "Funds Discrepancy")
       

this did the trick Thanks.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39911773
You are welcome!

/gustav
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question