In AC97, I'm trying to create a database of reading done by employees. The records go into tblReqReadDocs (DocID (PK),TopicID,SubjectID,GroupID,DueDate)using the code below
from frmAddReqReadDocs that has lbxTopicID, lbsSubjectID, lbxGroupID, and tbxDueDate.
I would like the EmployeeID added to tblReqReadDocs based on the GroupID selected on the frmAddReqReadDocs so I can retrieve which Docs each employee read.
Each employee is assigned to a group. I have tblEmployees (EmployeeID, FirstName, LastName, etc.), and tblEmployeeGroup (EmployeeID, GroupID).
I think I need something like the following in the code:
Any suggestion?
Thanks,
Brian
from frmAddReqReadDocs that has lbxTopicID, lbsSubjectID, lbxGroupID, and tbxDueDate.
Code:
Private Sub cmdAddRecords_Click()
On Error GoTo Err_cmdAddRecords_Click
Dim lbx1 As ListBox, lbx2 As ListBox, lbx3 As ListBox, tbx1 As TextBox, SQL As String, DQ As String, itm, itm2
Debug.Print SQL
Set lbx1 = Me!lbxTopic
Set lbx2 = Me!lbxSubject
Set lbx3 = Me!lbxGroup
Set tbx1 = Me!tbxDueDate
DQ = """"
If lbx1.ListIndex = (-1) Then
MsgBox "No Topic Selected!"
ElseIf lbx2.ListIndex = (-1) Then
MsgBox "No Subject(s) Selected!"
ElseIf lbx3.ListIndex = (-1) Then
MsgBox "No Group(s) Selected!"
Else
Dim db As DAO.Database
Set db = CurrentDb
For Each itm In lbx3.ItemsSelected
For Each itm2 In lbx2.ItemsSelected
SQL = "INSERT INTO tblReqReadDocs (TopicID, SubjectID, DueDate, GroupID) " & _
"VALUES (" & lbx1.Column(0) & "," _
& lbx2.Column(0, itm2) & "," _
& "#" & tbx1 & "#" & ", " _
& lbx3.Column(0, itm) & ");"
db.Execute SQL, dbFailOnError
Next
Next
Set db = Nothing
End If
Set lbx1 = Nothing
Set lbx2 = Nothing
Set lbx3 = Nothing
Exit_cmdAddRecords_Click:
Exit Sub
Err_cmdAddRecords_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecords_Click
End Sub
I would like the EmployeeID added to tblReqReadDocs based on the GroupID selected on the frmAddReqReadDocs so I can retrieve which Docs each employee read.
Each employee is assigned to a group. I have tblEmployees (EmployeeID, FirstName, LastName, etc.), and tblEmployeeGroup (EmployeeID, GroupID).
I think I need something like the following in the code:
Code:
INSERT INTO tblReqReadDocs.EmployeeID from tblEmployees JOIN tblEmployeeGroup on GroupID
WHERE frmAddReqReadDocs.GroupID = tblEmployeeGroup.GroupID
For Each EmployeeID selected in tblEmployeeGroup
SQL = "INSERT INTO tblReqReadDocs (TopicID, SubjectID, DueDate, GroupID,EmployeeID) " & _
"VALUES (" & lbx1.Column(0) & "," _
& lbx2.Column(0, itm2) & "," _
& "#" & tbx1 & "#" & ", " _
& lbx3.Column(0, itm) & "," _
& need something here & ");"
Any suggestion?
Thanks,
Brian