• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 87
  • Last Modified:

Forms controls and VBA

Hi Experts

I have four controls on a form as below:
1.      Total sales
2.      Cash Received
3.      Change
4.      Shortage
The shortage control will only filled in if the cash received is less than total sales , quite okay I have this VBA Code below , but I want the message part to be showing numbers or amount showing as shortage in the string as well.
If (Me.TotalSales > Me.CashReceived) Then
Beep
MsgBox “Please note that you received not enough cash for this transaction”
Cancel = True
Exit Sub
End If

Now suppose the shortage amount is $20, our business rule require that in the message the $20 should appear as well, example:
MsgBox “Please note that you have received not enough cash for this transaction, and so you have a shortage of $20, please check again”
0
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Asked:
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
1 Solution
 
Gustav BrockCIOCommented:
It could be like:

Dim Shortage As Currency

Shortage = Nz(Me.TotalSales, 0) - Nz(Me.CashReceived, 0)
If Shortage > 0 Then
    Beep
    MsgBox "Please note that you received not enough cash for this transaction," & _
         "and so you have a shortage of " & Format(Shortage, "Currency") & "." & _
         "Please check again." 
    Cancel = True
    Exit Sub
End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now