format a number in code

  • Thread starter Thread starter John Watkins
  • Start date Start date
J

John Watkins

I have a check box on a financial control that I use to
input financial transactions, much like a checking
register. I have a check box on it named "deposit" if it
is set to yes then the entry is a deposit and if it is
false then the entry is a withdrawl. Is there a way to
format the number in VB code?

I have tried using an form_Close event and converting the
number by multiply the amount by negative one, but if the
entry is ever reopened, the now negative number will be
converted to a positive.

Can anyone help me? I am hoping to put something into
code using an if then else if statement for the true and
false and have the command format the number.

John
(e-mail address removed)
 
Just a little clarification on this one.....

You have two controls on a form.
1 being a check box, which is boolean False for W/D and
True for deposit
2. A text box storing the amount to be transactioned(??is
that word?)

If this is the case I would do an if..then statement for
each record. Look at the value of the boolean box then
based on that do the multiplier to make the number
negative or positive

if not(checkbox) then 'if not checkbox is true then -- if
it is false
amount = amount *-1
end if

HTH.

MW

mweyland @ mnqio . sdps . org
 
For postive set to Abs([Field]), which always returns positive. For
negative use Abs([Field])*-1, which always returns a negative even if the
original was negative. Abs is the absolute function.

Kelvin
 
John said:
I have a check box on a financial control that I use to
input financial transactions, much like a checking
register. I have a check box on it named "deposit" if it
is set to yes then the entry is a deposit and if it is
false then the entry is a withdrawl. Is there a way to
format the number in VB code?

I have tried using an form_Close event and converting the
number by multiply the amount by negative one, but if the
entry is ever reopened, the now negative number will be
converted to a positive.

Can anyone help me? I am hoping to put something into
code using an if then else if statement for the true and
false and have the command format the number.


I'm not 100% sure what you're trying to do here, but I
suspect that you need to use the AfterUpdate event of both
the amount text box and the check box. Assuming that
deposits are always negative and other transactions are
positive, the code could be:

If Me.chkDeposit <> False Then
Me.txtAmount = -Abs(Me.txtAmount)
Else
Me.txtAmount = Abs(Me.txtAmount)
End If
 
John said:
I have a check box on a financial control that I use to
input financial transactions, much like a checking
register. I have a check box on it named "deposit" if it
is set to yes then the entry is a deposit and if it is
false then the entry is a withdrawl. Is there a way to
format the number in VB code?

I have tried using an form_Close event and converting the
number by multiply the amount by negative one, but if the
entry is ever reopened, the now negative number will be
converted to a positive.

Can anyone help me? I am hoping to put something into
code using an if then else if statement for the true and
false and have the command format the number.

John
(e-mail address removed)

Don't use the Form_Close event. Use the After_Update event
of the check box and of the amount field. Don't use the After_Update
event of the Form. This way the program will only change the amount
if the user changes the transaction by changing the check box or
changes the amount.

The next time the record is viewed, nothing will change unless
the user changes the check box or the amount.

Ron
 
Back
Top