Hi there. Is it true that you cannot update a recordset if it has a group by clause? Im trying to make sure that a tutor has space (TU_SPACE) and then decrease their space by one when a student is assigned to them but the following results in "cannot update database or object is read only" (highlighting rs2.edit)
I then tried making a variable out of space and doing it that way but it says "Item not found in this collection" Also if i did it this way how do i put the value of space back in the table for assigning the next student?
Has anyone any suggestions please!
Code:
strsql2 = "Select * From tblWorking "
Set rs = db.OpenRecordset(strsql2)
With rs
Do While Not .EOF 'Loop through the nursing students
course = rs("STU_COURSE_CODE") 'Get the students course
fac = DLookup("[CS_FAC_NO]", "tblCourse", "CS_CODE = '" & course & "'")
'Selects the first tutor in the nursing department with free space
strsql3 = "SELECT TOP 1 tblTutor.TU_CODE " _
& "FROM tblTutor " _
& "GROUP BY tblTutor.TU_CODE, tblTutor.TU_CHAMBER_SIZE, tblTutor.TU_DP_NO, tblTutor.TU_SPACE " _
& "HAVING ([TU_CHAMBER_SIZE] > tblTutor.TU_SPACE) AND (tblTutor.TU_DP_NO = 57) "
Set rs2 = db.OpenRecordset(strsql3)
If rs2.RecordCount <> 0 Then 'Assigns the student to this tutor
rs.Edit
rs!STU_TU_CODE = rs2!TU_CODE
rs.Update
rs2.Edit
rs2!TU_SPACE = rs2!TU_SPACE - 1
rs2.Update
End If
I then tried making a variable out of space and doing it that way but it says "Item not found in this collection" Also if i did it this way how do i put the value of space back in the table for assigning the next student?
Code:
Set rs2 = db.OpenRecordset(strsql3)
freespace = rs2("TU_SPACE")
If rs2.RecordCount <> 0 Then 'Assigns the student to this tutor
rs.Edit
rs!STU_TU_CODE = rs2!TU_CODE
rs.Update
freespace = freespace - 1
End If
Has anyone any suggestions please!