How to make a table show the #s in a form text box that added #s

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form where the user puts in numbers. Then on that form I have a
text box that adds those numbers with an expression under "control source".
However, by doing that, I cannot get those numbers to show up on the table.

How can I make numbers add on a form and have that number show up on the
table?
 
Hi
I am NOT an MVP but have been there! I put together a small form to test
your situation with with 4 Controls having the names: "txtNumber1",
"txtNumber2", "txtSum" for the control holding the Sum of txtNumber1 and
txtNumber2, and a Button called "cmdCalculate" which when clicked, causes
the
sum of txtNumber1 and txtNumber2 and places the result into txtSum:

Here is the code behind cmdCalculate

Private Sub cmdCalculate_Click()
Me.txtSum.Value = CDbl(Me.txtNumber1.Value) + CDbl(Me.txtNumber2.Value)
End Sub

To try it , create the new form with these controls (use a textbox for
controls with the "txt" prefix) and the button cmdCalculate. The Form name
(in the Form's Properties) can be anything you want but not null/empty/blank.

Note that the values are converted to doubles and summed to the value
of the form (Me) in the control calld Me.txtSum.Value. I use the "Me"
program reference to refer to the open form where i am executing the
code within that form. "Me" is very very useful.

If you dont see the values in the Me.txtSum, then refresh the form.

You can use other datatypes depending on your situation. Among them are:
Decimal, Single, Long....etc etc
 
If you are storing the numbers that make up the Total, then there is no
reason to store the Total. You can (and should) always calculate the total
when needed.

If you are only storing the total, then set the control's control source to
the total field in the table.
In the vba module for the form create a small sub that calculates the total
and assigns the value to your control.

Now, call that sub from the after update event of each of the controls where
the user is inputting numbers to be added to the total.

If you feel you really have to store both the numbers and the total, the
above will work to do that also.


"macro to email report not as attachment"
 
Back
Top