Form Calculations

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

Guest

Hello,
Is there a way to calculate a form field from two other form fields in the
same form? I would like the user to be able to enter a number in Field 1, a
percentage in Field 2, and then calculate Field 1 * Field 2 = Field 3. I
tried to do this by changing the properties for Field 3 but I didn't get the
desired result.

Also, once Field 3 is calculated, I would like the form to automatically
skip over it so that the user does not accidentally write over the calculated
value.

Any help would be greatly appreciated.

Thanks,
Sean Heckathorne
 
Are you talking about a Word form? If so, you would do better to ask in a
Word group. This group is for Access, a relational database program.
 
Sean said:
Hello,
Is there a way to calculate a form field from two other form fields in the
same form? I would like the user to be able to enter a number in Field 1, a
percentage in Field 2, and then calculate Field 1 * Field 2 = Field 3. I
tried to do this by changing the properties for Field 3 but I didn't get the
desired result.

Also, once Field 3 is calculated, I would like the form to automatically
skip over it so that the user does not accidentally write over the calculated
value.

Any help would be greatly appreciated.

Thanks,
Sean Heckathorne
Sean...
If you're refering to VBA, you access any field from any form within the same
document. Just make sure you're referencing the object correctly.

iNum = CInt(tNum.Text)
iPercent = CInt(tPercent.Text)
iPercent = iPercent * .01
iAnswer = iNum * iPercent

frm1.txtAnswer.Text = iAnswer
frm1.txtAnswer.Enabled = False

....my stab at it
 
First off when you create your form the table that contains your data must be
used in order to select the correct data fields.

1. Create your form with the two fields containing your data, "field1" and
"field2". Select the fields and place them on the form "form1".

2. Then place a blank "text box" from the controls list onto the form. On
the properties field "controlsource" of the "text box", select "Expression
Builder" and then select "form1" if that is the name of your form. When you
select "form1" you will see the fields attached to form1. It should contain
"field1" and "field2".

3. Select "field1" and paste to the expression box, select "*" and then
select "field2". The experession will look like this "field1*field2". Once
you close the expression box the expression will look like this
"=field1*field2" in the "ControlSource" field. Copy this expression to the
Events tab "Before Update" and "After Update" Properties fields.

4. In order to lock your text box so no one will modify it, go to
"properties" on the text box that contains your formula and then to the
"Data" tab and select the locked field "Yes"

Tom
 
Thanks tome, that worked exactly as I wanted it to. I'm having one more
problem though. I'm testing out the formula, and "field 2" is a percentage.
When I try to enter in a value like 16%, I type .16, but when I press enter,
the text field resets to 0.00%. I tried setting the number of decimal places
to 2 or 3 or 4 but nothing seemed to work. Thanks again.

-Sean Heckathorne
 
Hi H,

Make the following adjustments, and this should fix your problem.

"Table1', "Field2" must have the following properties adjusted.
"Field size" = "single"
"Format" = "Percent"
"Decimal Places" = "Auto"
"Default value" = "0"
"Validation Rule" = "<1"

"Form1", "field2" properties must be modified to display this input.
"Format" = "percentage"

Tom
 
Perfect, thanks Tom. My problem before was that I was just focusing on the
properties in the form but not on the properties in the table. It never hit
me that since they're related they should also have related properties.
 
Back
Top