Calculated Field

christshis

Registered User.
Local time
Today, 10:33
Joined
May 24, 2006
Messages
14
Hello Guys,

I am trying to do the following in a form.
1) (Travel hours + work hours) * dollarperhr to get the "Total" bill to a customer.

2) The results will be put in a field "TotalDollars" that is a part of a table.

Please help.

I tried to put an event (on change) on the "dollarperhr" box so that after entering the values in "travel hours" + "Work hours" * "dollarperhr", the calculation will be done to populate "TotalDollars", but it didn't work.

please help
 
You will need to use the AfterUpdate event of each of the controls on the form. If the other controls have been completed then go ahead and complete the TotalDollars control with:
Me.txtTotalDollars = (Me.txtTravelHours + Me.txtWorkHours) * Me.txtDollarPerHr

Using your control names of course!
 
Thank you so much for replying so quickly. I appreciate your inputs, but if you don't mind, i need some more details. I am a newbie to VBA.

You will need to use the AfterUpdate event of each of the controls on Question? What do I put in the afterupdate event of each control?
All the controls in the form are pulled from the same table. the form. If the other controls have been completed then go ahead and complete the TotalDollars control with:
Me.txtTotalDollars = (Me.txtTravelHours + Me.txtWorkHours) * Me.txtDollarPerHr
What does the Me.txt means?
 
If you will supply the *exact* names of the 4 controls (not the fields to which they are bound, although the names may be the same) then I can supply you with the code to put in one of the controls and you can modify it for the others.
 
Thanks again for replying. Attached is a word document with the exact names of the controls as they appear in the form design view.

Thank you.
 

Attachments

Here's the code for the AfterUpdate event of the [Work Hrs] control.
Code:
Private Sub Work_Hrs_AfterUpdate()

If Len(Me.[Work Hrs]) > 0 And _
   Len(Me.[Travel Hrs]) > 0 And _
   Len(Me.[Dollar/Hr]) > 0 Then
   Me.[Total Dollars] = (Me.[Work Hrs] + Me.[Travel Hrs]) * Me.[Dollar/Hr]
End If

End Sub
This code would be the same in all of the AfterUpdate events of the three controls. It insists that *something* be entered in each of the three controls. You will only see [Total Dollars] change when all three controls have been completed but they can be completed in any order.

Here's a link about characters used in names that you might find helpful.
Special characters that you must avoid when you work with Access databases
 
Thank you so much. It worked. Took me sometime to get it clean (my spelling, etc) but it worked.
I really appreciate your patience and your understanding.

God bless.
 

Users who are viewing this thread

Back
Top Bottom