Hello Friends... I've tried to learn a lot about Vba the last days. And i have to finish a Project where i dont have much time left. Does anybody of you have an idea how to solve my problem?
I have a Database and created some queries. The one query, that is important is "qrySchuldenMitEmail", where a column named e-mail is.
Additionally i have a report named "qryGesamtschulden"
My plan is, that with a click on a button, access opens "Outlook" and imports all the e-mails from my query "qrySchuldenMitEmail" + attaches my report named "qryGesamtschulden" to the E-mail
My following code already opens Outlook and attaches my report, but the thing with the e-mail addresses doesn't work:
Code:Sub sendEmail() Dim oOutlook As Outlook.Application Dim oEmailItem As MailItem Dim rs As Recordset Dim customerEmail As String If oOutlook Is Nothing Then Set oOutlook = New Outlook.Application End If Set oEmailItem = oOutlook.CreateItem(olMailItem) With oEmailItem Set rs = CurrentDb.OpenRecordset("select [e-mail] from qrySchuldenMitEmail") If rs.RecordCount > 0 Then rs.MoveFirst Do Until rs.EOF If IsNull(rs![e-mail]) Then rs.MoveNext Else customerEmail = customerEmail & rs![e-mail] & ";" .To = customerEmail rs.MoveNext End If Loop Else MsgBox "Es gibt keine E-mail Adressen" End If .To = "" .Subject = "aktuelle Schuldenliste" .Display End With DoCmd.SendObject acSendReport, "qryGesamtschulden", "PDFFormat(*.pdf)" End Sub Private Sub Befehl3_Click() Call sendEmail End Sub
If somebody could fix my code and explain me what the problem is, i would be really really happy!!!
have a nice day,
luffy