Insert Statement

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Insert Statement

Post by burrina »

I have a Main form with 2 subforms on it. It is used for Employee Expense Reports.
Main form uses query with tblEmployees and tblExpenseReports
Subform1 uses tblExpenseDetails
Subform2 uses tblExpensePayments

So that an employee can enter expense deductions and expense payments.

I need to insert 2 amounts from those subforms into another table.
Subform1 that uses tblExpenseDetails needs to insert (ExpenseItemAmount) into tblHour
Subform2 that uses tblExpensePayments needs to insert (ExpensePayment) into tblHour

Of course it needs to be for the Employee on the main form which uses a combo to select the employee.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

When do you want this to happen?
Do you want to insert the data for the current record in each of the subforms, or for all records in the subforms, or ...?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

My thinking is that it needs to the AfterUpdateEvent and for all of the records since you can have many records per subform. i.e. multiple expense deductions and multiple expense payments for that employee. Therefore the sum of them!

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

And is the EmployeeID the only link?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

The subforms are of course linked.
Subform1 is linked by ExpenseReportsID which is for Expense Deductions
Subform2 is linked by EmployeeID and ExpenseReportsID

They both have a Fake Key named txtemployeeid that refers to the main form PK which is EmployeeID

Here is a stab at the code.

'Add Expense Item Amount into tblHour Per Employee.
Dim strSQL As String

strSQL = "INSERT INTO tblHour (ExpenseTotals) "
strSQL = strSQL & "VALUES (#" & Me.txtPaymentTotal & "')"
CurrentDb.Execute strSQL, dbFailOnError


'Add Expense Item Amount into tblHour Per Employee.
Dim strSQL As String

strSQL = "INSERT INTO tblHour (ExpenseTotals) "
strSQL = strSQL & "VALUES (#" & Me.ExpenseItemAmount & "')"
CurrentDb.Execute strSQL, dbFailOnError

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

Will there be only one record per EmployeeID in tblHour?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

Yes and No. You can enter that same employee many times during the current payroll week but of course the expense data should be for that week and employee as well.
Exanple: I can enter James Browns payroll data as an Absence Day and then on a separate record enter payroll hours.
Either way, the expense report data should only be entered once regardless. Payroll form is filtered by current week as well is Expense Report form.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

So presumably we must enter more information than just ExpenseTotals in the table. Can you provide ALL relevant information, please?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

Main Expense Report Form. Record Source is qryExpenseReports that includes tblEmployees and tblExpenseReports linked by EmployeeID
subform for Expense Deduction uses qryExpenseReportDetails which uses tblExpenseDetails
subform for Expense Payments uses tblExpensePayments

Payroll form uses tblHour and PK is HoursID with FK of EmployeeID

Expense Deductions subform is linked by ExpenseReportID
Expense Payments sybform is linked by EmployeeID and ExpenseReportID

You select a Employee from combo on main Expense Reports form and then enter data for that employee on the subforms.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

I'd like to know which data besides ExpenseTotal and EmployeeID need to be entered in tblHour. I assume that HourID is an AutoNumber field, so we won't have to fill that ourselves.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

Yes, HoursID is a number and the PK. EmployeeID and txtPaymentTotal and EmployeeID and ExpenseItemAmount

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

I'm afraid I don't see how this would work, since there is no reference to the pay period.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

The reference to the pay period is in the record source for the main form. Between BeginDate and EndDate which is on another form.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

But shouldn't the pay period be in tblHour?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

The pay period is in tblHour and is set via frmMain which can be changed for whatever so as to view criteria.
Al forms show the date criteria that is filtered via the main form so that normally you would only see the current weeks data on any form.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

Does this mean that tblHour is a kind of temporary table?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Insert Statement

Post by burrina »

NO. The Main form of the db is where ALL date criteria is set. In most all of the queries it refers to the dates on the main form.
tblHour is a very important table since it contains all of the payroll data.

User avatar
HansV
Administrator
Posts: 78588
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Statement

Post by HansV »

As before, I have to admit defeat. I fail to grasp how this would work. Sorry.
Best wishes,
Hans