strSQL = "SELECT * FROM tblEmail WHERE ([Email] Is Not Null)"
With CurrentDb.OpenRecordset(strSQL)
'Records doorlopen, en rapport voor elk record instellen en mailen
.MoveLast
.MoveFirst
iAantal = .RecordCount
If iAantal = 0 Then Exit Sub
Do While Not .EOF
DoCmd.OpenReport sRapport, acViewDesign, , , acHidden
sTabel = Reports(sRapport).RecordSource
If InStr(1, UCase(sTabel), "WHERE") > 0 Then
strSQL_Rapport = Left(sTabel, InStr(1, sTabel, "WHERE ") - 1)
Else
If InStr(1, UCase(sTabel), "SELECT") = 0 Then
If InStr(1, sTabel, " ") > 0 And InStr(1, sTabel, "[") = 0 Then
sTabel = "[" & sTabel & "]"
End If
strSQL_Rapport = "SELECT * FROM " & sTabel & " "
Else
strSQL_Rapport = sTabel
End If
End If
'Extra loopje, om de punt-komma's te verwijderen.
Do Until Right(strSQL_Rapport, 1) <> ";"
strSQL = Left(strSQL_Rapport, Len(strSQL_Rapport) - 1)
Loop
'Klantfilter op rapport zetten
sFilter = " WHERE (Klantnummer =" & !KlantID & ");"
strSQL_Rapport = strSQL_Rapport & sFilter
Reports(sRapport).RecordSource = strSQL_Rapport
DoCmd.Close acReport, sRapport, acSaveYes
'Controle of een mailadres aanwezig is
'Factuur verzenden
DoCmd.SendObject acSendReport, sRapport, acFormatSNP, !Email, , , "Van Zomerschool voor " _
& !Volledigenaam, " Hierbij het bericht voor uw activiteit(en) Zomerschool 2013", True
.MoveNext
Loop
.Close
End With