Hi
I am trying to delete data from two table when a button is clicked.
I have
Table:
- Employee
- Project
- Element
- EmpToProj (EmpID, ProjID)
- Timesheet (EmpID,ProjID,ElementID, TaskID, hours)Etc
Form Contains
1. lstEmployee : List Box which has employees list
2. lstAssigned: List Box which has Projects that are assigned to the employee
3. lstAvailable: List Box which has Projects that are yet to be assigned to the employee
I have " ADD " and "REmove" buttons.
When I click a project from the "lstAssigned" and click the remove button:
The project have to be removed from EmpToProj Table and also from Timesheet.
The Query I am using is:
Private Sub cmdRemove_Click()
On Error GoTo cmdRemove_Click_Error
Dim sSQL As String
Dim nMid As Long 'Member
Dim nWid As Long 'Event
Dim varRow As Variant
Dim ctlChosen As Control
If Len(lstEmployee.Column(0) & vbNullString) = 0 Then
MsgBox "There is no Member selected.", vbOKOnly + vbInformation, " I N P U T N E E D E D "
Exit Sub
End If
nMid = lstEmployee.Column(1)
'Check that at least one item has been selected
If lstAssigned.ItemsSelected.Count = 0 Then
MsgBox "Please select an event to remove from this Members's list.", vbOKOnly + vbInformation, _
" I N P U T N E E D E D "
lstAssigned.SetFocus
Exit Sub
End If
Set ctlChosen = lstAssigned
For Each varRow In ctlChosen.ItemsSelected
nWid = ctlChosen.Column(0, varRow)
sSQL = "DELETE * FROM EmpToProj WHERE EmployeeID = " & nMid & " AND ProjectID = " & nWid & ";"
CurrentDb.Execute sSQL, dbFailOnError
lstAvailable.Requery
lstAssigned.Requery
Next varRow
cmdRemove_Click_EXIT:
Set ctlChosen = Nothing
Exit Sub
cmdRemove_Click_Error:
Select Case Err
Case Else
Call fcnLogError(Err.Number, Err.Description)
End Select
Resume cmdRemove_Click_EXIT
End Sub
This query helps in removing the project from Emp to project table.
But now I want to remove this from Timesheet table too.
Please help me with this.
Thanks