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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding additional info to an existing record

Status
Not open for further replies.

Danielle17

Technical User
Apr 17, 2001
102
US
I have a small program that allows a user to schedule an "On-Site Job" There is a form that the user fills in, the info is stored, and a report is created. Now after this report is given to a technician and the job is completed I would like to enter the trip expenses into that same job record. I thought that I could create another form that would prompt the user to enter lodging, meals, and gas expenses and the another text box on that form would calculate the total right away. I know how to do this but I'm unsure on how the code would look so that it would find the correct record(every job has an autonumber assigned to it, it's also the primary key). In the past I have tried to create an edit form so that a record could be edited but all that did was cause problems and I had a lot of clean up work after that. I was wondering if anyone here could help me out with the code before I go and make a mess :-Þ Thanks
 
Here's the code that I already have for the Command button of the form:

Private Sub cmdEnter_Click()

Dim db As Database
Dim rsExpense As Recordset

Set db = CurrentDb
Set rsExpense = db.OpenRecordset("zJobTable")

If Me.txtLodging = "" Then
Me.txtLodging = 0
End If

If Me.txtMeals = "" Then
Me.txtMeals = 0
End If

If Me.txtGas = "" Then
Me.txtGas = 0
End If

If Me.txtMisc = "" Then
Me.txtMisc = 0
End If



rsExpense("LodgingCost") = Me.txtLodging
rsExpense("MealsCost") = Me.txtMeals
rsExpense("GasCost") = Me.txtGas
rsExpense("MiscCost") = Me.txtMisc
rsExpense("TotalCost") = Me.txtTotal


End Sub

How do I get the Totals text box on my form to equal the sum of 4 other expense text boxes on that same form? I've tried the expression builder but I'm unsure where to put it....OnFocus, Onclick....
 
Hi Danielle

Try putting your code in the OnChange event of your four expenses textboxes. This will then recalculate every time any one of the four textboxes changes value

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top