Run Time error 424 - Object Required

jex57

Board Regular
Joined
Oct 29, 2015
Messages
62
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
look at these two lines very closely

Do Until rsTbl2.EOF
For Each fld In rstb12.Fields


I'll give you a hint
there's more than eleven errors and less than thirteen :)
 
Upvote 0
Fixed the error but the update does not work.
Please can someone assist.
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
 
Upvote 0
Maybe there really are more than 11 and less than 13!;)
!StudentID = strudent

Have to say I don't get the idea of cycling through the fields of a table looking for more than one called "reg_year".
Advice: you should always allow for the possibility that a recordset contains no records, otherwise you will generate an error when you try to MoveFirst. It's just good form.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,248
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top