Hey all!
I'm currently working on a database for a payroll system. I've created all the tables and the queries to calculate wages, etc, as well as forms so that the user can add/delete/edit/view records.
There is an employee table containing details about an employee (employee id - primary key, name, surname, project id - references project table, occupation id - references occupation table, etc). There are also tables containing each employee's hours worked, total income, total deductions, etc.
When a new employee is added to the database, a new record must be created for him/her in the following tables: hours_worked, income_deductions_wages, total_deductions, total_wages and obviously the employee table.
Here is my VBA code that creates the new record in he employee table, and then inserts a new record into the hours_worked table. i want it to take the employee_id and project_id from the form which has the data fro the new employee record. At the moment, all this code does is create the new record in the Employee table.
When an employee is removed from the database, all the records related to that employee must also be deleted.
i have queries to delete the record from each table. they are all as follows, just with different table names.
FrmEmployee_ID is the name of the textbox on the form. FrmEmployee is the Employee_ID of the record to delete. At the moment, when i choose to delete an employee record, a textbox pops up asking me to enter the FrmEmployee_ID. It does that for all 7 queries. I want the query to either take the FrmEmployee_ID from the active record, or alternatively, only enter it once but i don't know how to do that.
the VBA code is as follows:
Any help would be much appreciated.
Regards
Laura
I'm currently working on a database for a payroll system. I've created all the tables and the queries to calculate wages, etc, as well as forms so that the user can add/delete/edit/view records.
There is an employee table containing details about an employee (employee id - primary key, name, surname, project id - references project table, occupation id - references occupation table, etc). There are also tables containing each employee's hours worked, total income, total deductions, etc.
When a new employee is added to the database, a new record must be created for him/her in the following tables: hours_worked, income_deductions_wages, total_deductions, total_wages and obviously the employee table.
Here is my VBA code that creates the new record in he employee table, and then inserts a new record into the hours_worked table. i want it to take the employee_id and project_id from the form which has the data fro the new employee record. At the moment, all this code does is create the new record in the Employee table.
Code:
Private Sub CmdAddRecord_Click()
On Error GoTo Err_CmdAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'Prevent user warnings
DoCmd.SetWarnings False
Dim SQL As String
SQL = "INSERT INTO employee_hours_worked_table values(frmEmployee_id,project_id ,0,0,0,0);"
DoCmd.RunSQL SQL
'Allow user warnings
DoCmd.SetWarnings True
Exit_CmdAddRecord_Click:
Exit Sub
Err_CmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_CmdAddRecord_Click
End Sub
When an employee is removed from the database, all the records related to that employee must also be deleted.
i have queries to delete the record from each table. they are all as follows, just with different table names.
Code:
DELETE *
FROM other_pay_table
WHERE employee_id=FrmEmployee_ID;
FrmEmployee_ID is the name of the textbox on the form. FrmEmployee is the Employee_ID of the record to delete. At the moment, when i choose to delete an employee record, a textbox pops up asking me to enter the FrmEmployee_ID. It does that for all 7 queries. I want the query to either take the FrmEmployee_ID from the active record, or alternatively, only enter it once but i don't know how to do that.
the VBA code is as follows:
Code:
Private Sub CmdDelete_Click()
On Error GoTo Err_CmdDelete_Click
Dim SQL As String
'Prevent user warnings
DoCmd.SetWarnings False
DoCmd.OpenQuery "delete_record_allowances_pay_table"
DoCmd.Close acQuery, "delete_record_allowances_pay_table"
DoCmd.OpenQuery "delete_record_other_pay_table"
DoCmd.Close acQuery, "delete_record_other_pay_table"
DoCmd.OpenQuery "delete_record_employee_hours_worked_table"
DoCmd.Close acQuery, "delete_records_employee_hours_worked_table"
DoCmd.OpenQuery "delete_record_employee_income_deductions_wages_table"
DoCmd.Close acQuery, "delete_record_employee_income_deductions_wages_table"
DoCmd.OpenQuery "delete_record_employee_total_deductions_table"
DoCmd.Close acQuery, "delete_record_employee_total_deductions_table"
DoCmd.OpenQuery "delete_record_employee_total_wages_table"
DoCmd.Close acQuery, "delete_record_employee_total_wages_table"
DoCmd.OpenQuery "delete_record_employee_table"
DoCmd.Close acQuery, "delete_record_employee_table"
'Allow user warnings
DoCmd.SetWarnings True
Exit_CmdDelete_Click:
Exit Sub
Err_CmdDelete_Click:
MsgBox Err.Description
Resume Exit_CmdDelete_Click
End Sub
Any help would be much appreciated.
Regards
Laura