I am getting the following error on the "For Each varItem In lstSelectedStudents" lineCode:Private Sub cmdSaveClass_Click() Dim MyDB As DAO.Database Dim varItem As Variant Dim lst As ListBox Dim rst As DAO.Recordset 'If lstApprovedTrainers.ItemsSelected.Count = 0 Then 'MsgBox "Please select at least 1 (one) trainer to add to this grant.", vbOKOnly, "Error" 'Exit Sub 'End If Set MyDB = CurrentDb Set rst = MyDB.OpenRecordset("tbl2ClassTaken", dbOpenDynaset, dbAppendOnly) With rst For Each varItem In lstSelectedStudents .AddNew ![StudentID] = lstSelectedStudents.ItemData(varItem) ![ClassID] = cboClassSelection ![ClassDate] = txtClassDate ![HoursTaken] = txtHoursTaken .Update Next varItem End With DoCmd.Close acForm, "frmAddClassRoster" rst.Close Set rst = Nothing DoCmd.Maximize End Sub
Run-Time Error '438'
Object doesn't support this property or method
Now I know this procedure works as I am using it on a different form. I changed all the information to reflect the new table I am trying to save to as well as referring to what fields I am trying to gather that information from. The other time it is used it just for selections in a listbox. This time I have created 2 listboxes. The first listbox contains all students that have ever been entered into the database. The second listbox contains only those that have been moved to the listbox from list1, removing it from list1 in the process. Any ideas on how to have the listbox cycled through similar to when .ItemsSelected is being used, but this time to have all that are listed.


Adding all items in ListBox
Reply With Quote

