Hello, can anyone tell me where i am going wrong please? Im trying to send an email to tutors who have student/s in a particular school which is entered by use of an input box.
At the moment i've created 2 recordsets. The first one finds out what courses are related to that school (as the student table only has course codes not school codes in it)
The second recordsets finds the tutors who have students in that school
Currently it is creating an email to only one of the tutors (but enters in their email address twice) Is it because of the way i am trying to loop through both recordsets?
sch = InputBox("Please enter the school number", , "School Number")
str2 = "Select [tblCourse].CS_CODE from [tblCourse] where [tblCourse].CS_SCH_NO = " & "" & sch & ";"
Set rs = db.OpenRecordset(str2)
code = rs("CS_CODE")
Do While Not rs.EOF
strsql = "Select DISTINCT [tblTutor].[TU_EMAIL] from [tblTutor] inner join [tblStudents] on [tblTutor].TU_CODE = [tblStudents].STU_TU_CODE " _
& "where tblStudents.STU_COURSE_CODE = '" & code & "'"
Set rs2 = db.OpenRecordset(strsql)
Do While Not rs2.EOF
If Not IsNull(rs2("TU_EMAIL")) Then
addresses = addresses & ";" & rs2("TU_EMAIL")
End If
rs2.MoveNext
Loop
rs.MoveNext
Loop
At the moment i've created 2 recordsets. The first one finds out what courses are related to that school (as the student table only has course codes not school codes in it)
The second recordsets finds the tutors who have students in that school
Currently it is creating an email to only one of the tutors (but enters in their email address twice) Is it because of the way i am trying to loop through both recordsets?
sch = InputBox("Please enter the school number", , "School Number")
str2 = "Select [tblCourse].CS_CODE from [tblCourse] where [tblCourse].CS_SCH_NO = " & "" & sch & ";"
Set rs = db.OpenRecordset(str2)
code = rs("CS_CODE")
Do While Not rs.EOF
strsql = "Select DISTINCT [tblTutor].[TU_EMAIL] from [tblTutor] inner join [tblStudents] on [tblTutor].TU_CODE = [tblStudents].STU_TU_CODE " _
& "where tblStudents.STU_COURSE_CODE = '" & code & "'"
Set rs2 = db.OpenRecordset(strsql)
Do While Not rs2.EOF
If Not IsNull(rs2("TU_EMAIL")) Then
addresses = addresses & ";" & rs2("TU_EMAIL")
End If
rs2.MoveNext
Loop
rs.MoveNext
Loop