Private Sub Mail_Click()
Dim Email As String, FileName As String, Filepath As String
Dim strSQL As String
Dim rs As Recordset
Dim qTmp As QueryDef
Dim sRapport As String
Dim folder As String
Dim tmp As String
On Error GoTo Err_Mail_click
Me.Dirty = False
sRapport = "rptPlanning"
strSQL = "SELECT * FROM QryPlanningmail WHERE [projectid] = " & Me.CboProjectNR & " Order by Email"
Set qTmp = CurrentDb.QueryDefs("TmpMail")
qTmp.SQL = strSQL
strSQL = "SELECT * FROM QryPlanning WHERE [Projectid]=" & Me.CboProjectNR
Set qTmp = CurrentDb.QueryDefs("tmpRapport")
qTmp.SQL = strSQL
tmp = InputBox("", "", strSQL)
strSQL = "SELECT * FROM TmpMail WHERE ([Email] Is Not Null And Not [Email] = """")"
Set rs = CurrentDb.OpenRecordset(strSQL)
If rs.RecordCount > 0 Then
Do Until rs.EOF
If Not Email = vbNullString Then Email = Email & ";"
Email = Email & rs!Email
rs.MoveNext
Loop
Else
MsgBox "Geen email adressen..."
Exit Sub
End If
Me.ProjectID.Requery
folder = CurrentProject.Path & "\verzondenmail\"
DoCmd.OutputTo acOutputReport, "RptPlanning", acFormatPDF, folder & Me!ProjectID & ".pdf"
''DoCmd.OpenReport "RpTPlanning", acViewPreview, , Me.Filter, acHidden
''DoCmd.SendObject acSendReport, "RptPlanning", acFormatPDF, Email, , , "Planning", True
sRapport = "SELECT * FROM TmpRapport WHERE (ProjectID=" & ProjectID & ")"
Set qTmp = CurrentDb.QueryDefs(strSQL)
qTmp.SQL = strSQL
DoCmd.OutputTo acOutputReport, "RptPlanning", acFormatPDF, folder & Me!ProjectID & ".pdf"
DoCmd.SendObject acSendReport, sRapport, acFormatPDF, Email, , , "Planning", True
DoCmd.Close acReport, "RptPlanning"
Err_Mail_click:
MsgBox Err.Description
If Len(Verzonden) = 0 Then
Verzonden.Value = False
Else
Verzonden.Value = True
End If
End Sub