I have a continuous form where I have made all the fields unbound. I wish to populate these with data derived from a query.
I have the following code:
Code:
Private Sub Form_Load()
Dim rst As Recordset
Dim rst2 As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tbl_class WHERE course_id=1")
course.Value = rst!course_id
Set rst2 = CurrentDb.OpenRecordset("SELECT * FROM qry_students_by_course WHERE course_id=" & CInt(course.Value))
txt_class.Value = rst2!txt_class_code
txt_name.Value = rst2!Name
txt_gender.Value = rst2!txt_gender
txt_meg.Value = rst2!txt_meg
txt_target.Value = rst2!txt_target
txt_school_name.Value = rst2!txt_school_name
txt_du.Value = rst2!DU
txt_sen.Value = rst2!SEN
txt_ethnicity.Value = rst2!txt_ethnicity
rst2.MoveNext
End Sub
The form loads and the number of rows equals the number of records I am expecting. The form however is populated only with the first record from the query; so I have about 40 copies of the same record rather than the 40 individual records I am expecting.
I put in the last line (MoveNext) with the thought that the code is being accessed each time by the system but even if this were true, the system would be starting from scratch each time so my question is simple:
How do I make the system populate the entire form correctly?