Amount as minus (on save)

  • Thread starter Thread starter Harmannus
  • Start date Start date
H

Harmannus

Hallo,

Is it possible to add a minus sign to an amount ons save (if a user forgot
to book a amount as minus)?

The field is called NetAmount and should ideally alsways be filled in with a
minus sign e.g. ? 50-

Or is there a way to make this default behavior for a field? So when
entering an amount the minus sign gets added automatically (if a user
forgets it)?

Regards,
Harmannus
 
If the amount is always going to be negative, just treat it as negative in
any further calculations and displays. Then on the rare cases where its
positive, ask the user to enter it as negative - eg a credit.


--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
I think you'd be taking a huge risk by assuming that a value is negative and
adjusting all your calculations from here to forever. That's a maintanence
error just waiting to happen.


You could add code to the AfterUpdate event on the form:

myValue = 0 - abs(myValue) ' This guarantees it will always be
stored as negative.
 
Bill Nicholson said:
I think you'd be taking a huge risk by assuming that a value is negative and
adjusting all your calculations from here to forever. That's a maintanence
error just waiting to happen.


You could add code to the AfterUpdate event on the form:

myValue = 0 - abs(myValue) ' This guarantees it will always be
stored as negative.

Both solutions offer problems but always forcing it to minus if it can ever
be positive will cause problems that can't be solved in a form.
 
How about using the AfterUpdate event of the control to examine its Text
property. If the Text contains a Plus nor a Minus character, accept it as
entered. Otherwise negate the value.

That makes the field default to negative, but allows the user to specify a
positive if necessary.

Private Sub Amount_AfterUpdate()
With Me.Amount
If (Len(.Text) > 0) And (Instr(.Text, "+") = 0) And (Instr(.Text,
"-") = 0) Then
.Value = - .Value
End If
End With
End Sub
 
Hallo,

Thanx for the replies!

Enough information/solutions to get me (re)think how to handle this input
;-)


Regards,
Harmannus
 
Maybe it wasnt clear what I meant. If you have a value, like say a bank
balance, where the debits always come out of an account, then you could
enter debits as negative, so the balance = credits + debits. But if you
treat debits as 'really' negative, then we would write balance = credits -
debits, it makes it easier to input debits as positive, and always treat
them as negative. Then in the rare case where the bank makes an entry
error, you can still have a negative amount entered as a debit, and all the
calculations still work without any problems.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
Back
Top