R
ridders
Hi
I have the following code linked to a multi select list box (LstPupils):
-----------------------------------------------------
Set ctl = Forms!SelectReview.LstPupils
For Each varitm In ctl.ItemsSelected
strPupilID = ctl.ItemData(varitm)
strsql1 = " SELECT PupilData.PupilID, PupilData.Surname, PupilData.Forename,
PupilData.Gender, " & _
" PupilData.DateOfBirth, PupilData.YearGroup, PupilData.TutorGroup,
PupilData.Active," & _
" StudentAddresses.[Parental Salutation], StudentAddresses.AddressBlock,
StudentAddresses.LetterText, Teachers.TeacherID, " & _
" Teachers!Title & ' ' & Left(Teachers!Forename,1) & ' ' &
Teachers!Surname AS TeacherName" & _
" FROM Teachers, PupilData INNER JOIN StudentAddresses ON
PupilData.PupilID = StudentAddresses.PupilID"
strWhere = "((PupilData.PupilID = '" & strPupilID & "') And
(PupilData.Active) = Yes) And (Teachers.TeacherID = GetCurrentTeacher())"
strOrder = " PupilData.Surname, PupilData.Forename"
strSQL = strsql1 & " WHERE " & strWhere & " ORDER BY " & strOrder
Next varitm
Debug.Print strSQL
MergeAllWord strSQL, "MergeTemplates"
--------------------------------------------------
The code listed just runs the last selected record.
What do I need to change to run all the selected records?
Note: The final line of code runs a mail merge function as supplied by
Albert Kallal
I have the following code linked to a multi select list box (LstPupils):
-----------------------------------------------------
Set ctl = Forms!SelectReview.LstPupils
For Each varitm In ctl.ItemsSelected
strPupilID = ctl.ItemData(varitm)
strsql1 = " SELECT PupilData.PupilID, PupilData.Surname, PupilData.Forename,
PupilData.Gender, " & _
" PupilData.DateOfBirth, PupilData.YearGroup, PupilData.TutorGroup,
PupilData.Active," & _
" StudentAddresses.[Parental Salutation], StudentAddresses.AddressBlock,
StudentAddresses.LetterText, Teachers.TeacherID, " & _
" Teachers!Title & ' ' & Left(Teachers!Forename,1) & ' ' &
Teachers!Surname AS TeacherName" & _
" FROM Teachers, PupilData INNER JOIN StudentAddresses ON
PupilData.PupilID = StudentAddresses.PupilID"
strWhere = "((PupilData.PupilID = '" & strPupilID & "') And
(PupilData.Active) = Yes) And (Teachers.TeacherID = GetCurrentTeacher())"
strOrder = " PupilData.Surname, PupilData.Forename"
strSQL = strsql1 & " WHERE " & strWhere & " ORDER BY " & strOrder
Next varitm
Debug.Print strSQL
MergeAllWord strSQL, "MergeTemplates"
--------------------------------------------------
The code listed just runs the last selected record.
What do I need to change to run all the selected records?
Note: The final line of code runs a mail merge function as supplied by
Albert Kallal