Adding data from text box to table

A

Amour

Please help
I have a form that has mileage (mileage = miles * rate). I want the user to
enter in the amout of miles than my program uses formula to auto update the
field within the form plus the table.

In the control source I have a bound field called Mileage (this is the name
of a field on the table)
In the default I have =[Forms]![frmTravel]![MilAmt]*0.485

Now when I put =[MilAmt]*0.485 in the control source it works auto on the
form (but that does not update the table). I also have tried this on the
default (still does not work)
What am I doing wrong..
Thank You.
 
K

kingston via AccessMonster.com

Create an event procedure on the textbox where the user enters information.
Right-click on the input box and open the Properties window. In the Event
tab, select [Event Procedure] and click on the ... button at the end of the
line. The VB window will open. Type Me.Mileage = Me.MilAmt*0.485. I'm
assuming that the mileage field is actually bound to a control called Mileage.
If it isn't, use the correct name. This will set the value in the form and
in the table. When you exit the record, the data will be saved in the table.

What you're doing is setting the default value of the control. The control
belongs to the form (not the table) and just displays data from the data
source or what you've explicitly told it to display. Something else you may
want to consider if you haven't already is why store data that can be
calculated so easily? In other words, once you have the data [miles] and
[rate] stored, [mileage] is automatic. hth
Please help
I have a form that has mileage (mileage = miles * rate). I want the user to
enter in the amout of miles than my program uses formula to auto update the
field within the form plus the table.

In the control source I have a bound field called Mileage (this is the name
of a field on the table)
In the default I have =[Forms]![frmTravel]![MilAmt]*0.485

Now when I put =[MilAmt]*0.485 in the control source it works auto on the
form (but that does not update the table). I also have tried this on the
default (still does not work)
What am I doing wrong..
Thank You.
 
J

Jeff Boyce

Amour

If you take a look through the tablesdbdesign newsgroup, you'll find a very
strong consensus against doing what you described. That is, there's rarely
a need to store a calculated value. It is generally sufficient (and faster)
to calculate the calculated value on-the-fly, in a query or a form or a
report. Besides, if you store a calculated value in a table, then someone
comes back and fixes a mistake they made in entering [miles], you'll have to
work out the code needed to keep the values accurate and synchronized!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
A

Amour

Thank You that worked as far as not inputting a calculated field. You see
that calculated field also gets added up for another Subtotal field. So that
is why I need this calculated field.

kingston via AccessMonster.com said:
Create an event procedure on the textbox where the user enters information.
Right-click on the input box and open the Properties window. In the Event
tab, select [Event Procedure] and click on the ... button at the end of the
line. The VB window will open. Type Me.Mileage = Me.MilAmt*0.485. I'm
assuming that the mileage field is actually bound to a control called Mileage.
If it isn't, use the correct name. This will set the value in the form and
in the table. When you exit the record, the data will be saved in the table.

What you're doing is setting the default value of the control. The control
belongs to the form (not the table) and just displays data from the data
source or what you've explicitly told it to display. Something else you may
want to consider if you haven't already is why store data that can be
calculated so easily? In other words, once you have the data [miles] and
[rate] stored, [mileage] is automatic. hth
Please help
I have a form that has mileage (mileage = miles * rate). I want the user to
enter in the amout of miles than my program uses formula to auto update the
field within the form plus the table.

In the control source I have a bound field called Mileage (this is the name
of a field on the table)
In the default I have =[Forms]![frmTravel]![MilAmt]*0.485

Now when I put =[MilAmt]*0.485 in the control source it works auto on the
form (but that does not update the table). I also have tried this on the
default (still does not work)
What am I doing wrong..
Thank You.
 
K

kingston via AccessMonster.com

Your Subtotal field could also be calculated on the fly: Sum([miles]*[rate])
Thank You that worked as far as not inputting a calculated field. You see
that calculated field also gets added up for another Subtotal field. So that
is why I need this calculated field.
Create an event procedure on the textbox where the user enters information.
Right-click on the input box and open the Properties window. In the Event
[quoted text clipped - 25 lines]
 
J

John W. Vinson

Thank You that worked as far as not inputting a calculated field. You see
that calculated field also gets added up for another Subtotal field. So that
is why I need this calculated field.

Then do the calculation as a calculated field in the Query upon which the form
is based (rather than in a textbox on the form).

As noted elsethread, the calculated value should not be stored in any table
field.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top