In AC97, I have a tblReqReadDocs with fields docID (pk), TopicID, SubjectID, GroupID, and DueDate. I have a frmAddReqReadDocs with lbxTopic, lbxSubject (multi-select), lbxGroup (multi-select), and tbxDueDate. I would like to add records to the table for each combination of selections from the list boxes. If 4 subjects and 3 groups are selected, I would like 12 (4x3) records added, all with the same TopicID and DueDate.
I have the following code to add records, but only the first SubjectID is combined with each of the GroupID's.
I need all the combinations of TopicID, SubjectID, and GroupID to be added to the table.
I need a way to select the first GroupID, cycle through the SubjectID's and add the combinations to the table, and then select the next GroupID and repeat the process.
Thanks,
Brian
I have the following code to add records, but only the first SubjectID is combined with each of the GroupID's.
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
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
For Each itm In lbx3.ItemsSelected
SQL = "INSERT INTO tblReqReadDocs (TopicID, SubjectID, DueDate, GroupID) " & _
"VALUES (" & lbx1.Column(0) & "," _
& lbx2.Column(0) & "," _
& "#" & tbx1 & "#" & ", " _
& lbx3.Column(0, itm) & ");"
DoCmd.RunSQL SQL
Next
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 need all the combinations of TopicID, SubjectID, and GroupID to be added to the table.
I need a way to select the first GroupID, cycle through the SubjectID's and add the combinations to the table, and then select the next GroupID and repeat the process.
Thanks,
Brian