Question : Change a user-entered number on a form to negative

Hi,

This question has been asked several times but I need some additional information, as a relatively new user to MSAccess.  I have a text box on a form called [AMOUNT DISPERSED] which I want to store in the corresponding table as a negative number.  However, I don't want the user to have to key in a '-' before the number.

The accepted solution looks to be this:

Me!Field1 = Abs(Me!Field1) * -1

Where do I put this? II tried the following, which didn't work:

On the [AMOUNT DISPERSED] text box property sheet, on the Event tab, in the After Update property, I wrote:
=[AMOUNT DISPERSED]=Abs([AMOUNT DISPERSED])*-1

Any simple guidance would be appreciated.  Thanks.

Answer : Change a user-entered number on a form to negative

Select [Event Procedure] in the control's after update combobox then click on the button with three dots.

The line
[AMOUNT DISPERSED]=Abs([AMOUNT DISPERSED])*-1
goes into the code for the after update event like this:
Private Sub AMOUNT_DISPERSED_AfterUpdate ()
[AMOUNT DISPERSED]=Abs([AMOUNT DISPERSED])*-1
End Sub

Btw: It is best to avoid spaces, underscores and other special characters in your naming of objects. For example: txtAmountDispersed is just as easy to read as AMOUNT DISPERSED.  Objects named with special characters including spaces need to be placed in brackets for Access to recognize them correctly. Here is an extreme example of the problems you will have using special characters in your names:
I named a textbox
!@#$%^&*()_+= -{}:;"'<,>?/|~
and had Access create an event procedure.  Access converted the name of the textbox to:
Ctl_____________________________
so if the form had the name:
~!@#$%^&*()_+= -{}:;"'<,>?/|~
referencing the textbox would be:
Forms!l_____________________________!Ctl_____________________________
A useful tip for someone who doesn't want someone else (probably even themselves) from reading their code.
And spaces will sometimes cause problems in VBA references even after years of trouble free operation.

It is also a good idea to use a naming scheme such as Leszynski naming conventions (see references). It makes it clearer what type of object you are naming and it reduces the risk of duplicate name problems (like a control name and its control source).

References:
http://www.xoc.net/standards/rvbanc.asp
http://www.dhdurso.org/articles/ms-access-naming.html
http://www.acc-technology.com/namconv.htm
http://www.databasedev.co.uk/naming_conv.html
http://en.wikipedia.org/wiki/Leszynski_naming_convention
Random Solutions  
 
programming4us programming4us