Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating value from two text box fields 1

Status
Not open for further replies.

SHAWTY721

Programmer
Aug 16, 2007
116
US
Creating a form that needs to do some calculations. I am trying to get the code to take the value from one text field and divide it by the other text field and set my total field equal to the value of the calculation. Here is the code that I created when I click on the Calculate button I created I get this message : "You can't reference a property or a method for a control unless the control has the focus"

My Code:
Private Sub btnCalculate_Click()
On Error GoTo Err_btnCalculate_Click

'Calculates Full-Time Equivalent
Me.txtFTE.Text = Me.txtHours.Value / Me.txtWorkWeek.Value

Exit_btnCalculate_Click:
Exit Sub

Err_btnCalculate_Click:
MsgBox Err.Description
Resume Exit_btnCalculate_Click

End Sub

Thanks in advance for any help!
 
you can not access the text property of a control unless it has the focus " Me.txtFTE.Text", but you can the value property.

However why do you need a procedure to do this? You can just make "txtFTE" a calculated control. In the control source

=[txtHours] / [txtWorkWeek]

should update after you update the fields.
 
Code:
Me.txtFTE.Text = Me.txtHours.Value / Me.txtWorkWeek.Value

Just replace the "txtFTE.Text" to "txtFTE.Value"

you should be able to access Value without the focus!

Hope it helps

SG
 
MajP is there a way to have the calculated field appear in the database, so it can be used for report or analysis purposes later.

Thanks!
 
is there a way to have the calculated field appear in the database

Storing calculated data is rarely a good idea. When you create your report, include calculations at that time.

If you need it for historical purposes, you would create a field in your table, then bind the text box to that field.


Randy
 
I thought a calculated control couldn't be bound to a field.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top