Good day,
Please can someone review my code. I get a runtime error - Object Required in the line:
For Each fld In rstb12.Fields
What I need the code to do is the following:
Update a table named STUDENTS AND CLASSES
with information from the STUDENT table (copy all student Ids where the year is the same as the current year)
And then update table STUDENTS AND CLASSES with the classid based on a value that is displayed on a form
Any assistance would be greatly appreciated.
Thank you
Private Sub UpdateClass_Click()
Dim db As DAO.Database
Dim rsTbl1 As DAO.Recordset, rsTbl2 As DAO.Recordset
Dim class_list As String
Dim strClass As String, strStudent As String
Dim strTaskFreq As String, strTask As String
Dim blnSameSupv As Boolean
Dim Class_ID As Integer
Dim fld As Field
'DoCmd.Hourglass True
Set db = CurrentDb()
Set rsTbl1 = db.OpenRecordset("Students And Classes", dbOpenDynaset)
strClass = Forms![classes]![ClassID].Value
Set rsTbl2 = db.OpenRecordset("Students", dbOpenDynaset)
rsTbl2.MoveFirst
Do Until rsTbl2.EOF
For Each fld In rstb12.Fields
Select Case fld.Name
Case "reg_year"
strStudent = StudentID
If reg_year = Year Then
With rsTbl1
.AddNew
!ClassID = strClass
!StudentID = strudent
.Update
End With
End If
End Select
Next fld
rsTbl2.MoveNext
Loop
rsTbl1.Close
rsTbl2.Close
Set rsTbl1 = Nothing
Set rsTbl2 = Nothing
Set db = Nothing
' DoCmd.Hourglass False
Me.Repaint
DoEvents
End Sub
Please can someone review my code. I get a runtime error - Object Required in the line:
For Each fld In rstb12.Fields
What I need the code to do is the following:
Update a table named STUDENTS AND CLASSES
with information from the STUDENT table (copy all student Ids where the year is the same as the current year)
And then update table STUDENTS AND CLASSES with the classid based on a value that is displayed on a form
Any assistance would be greatly appreciated.
Thank you
Private Sub UpdateClass_Click()
Dim db As DAO.Database
Dim rsTbl1 As DAO.Recordset, rsTbl2 As DAO.Recordset
Dim class_list As String
Dim strClass As String, strStudent As String
Dim strTaskFreq As String, strTask As String
Dim blnSameSupv As Boolean
Dim Class_ID As Integer
Dim fld As Field
'DoCmd.Hourglass True
Set db = CurrentDb()
Set rsTbl1 = db.OpenRecordset("Students And Classes", dbOpenDynaset)
strClass = Forms![classes]![ClassID].Value
Set rsTbl2 = db.OpenRecordset("Students", dbOpenDynaset)
rsTbl2.MoveFirst
Do Until rsTbl2.EOF
For Each fld In rstb12.Fields
Select Case fld.Name
Case "reg_year"
strStudent = StudentID
If reg_year = Year Then
With rsTbl1
.AddNew
!ClassID = strClass
!StudentID = strudent
.Update
End With
End If
End Select
Next fld
rsTbl2.MoveNext
Loop
rsTbl1.Close
rsTbl2.Close
Set rsTbl1 = Nothing
Set rsTbl2 = Nothing
Set db = Nothing
' DoCmd.Hourglass False
Me.Repaint
DoEvents
End Sub