Hallo
Ik heb een vba programmatje die e-mails verstuurd uit een query.
En een rapport opslaat per record in de query in pdf.
Dit alles werkt perfect
Enkel wil ik nog die pdf meesturen met mijn e-mail (voor de movenext)
Maar ik krijg de volgende melding bij mijn MyMail.Attachments.Add
Dit is mijn vba code voor het maken van mijn e-mails. Het is misschien niet de perfecte mannier maar het werkt wel. De database is jammergenoeg te groot om online te plaatsen
Weet iemand hoe ik die melding weg krijgen en dus mijn bijlage (bestand op pc) kan meesturen.
Ik heb een vba programmatje die e-mails verstuurd uit een query.
En een rapport opslaat per record in de query in pdf.
Dit alles werkt perfect
Enkel wil ik nog die pdf meesturen met mijn e-mail (voor de movenext)
Maar ik krijg de volgende melding bij mijn MyMail.Attachments.Add
fout 91 tijdens uitvoering
objectvariabele of blokvariabele with is niet ingesteld
Dit is mijn vba code voor het maken van mijn e-mails. Het is misschien niet de perfecte mannier maar het werkt wel. De database is jammergenoeg te groot om online te plaatsen
Code:
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim ingcount As Long
Dim ingrscount As Long
Set fso = New FileSystemObject
' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application
' Set up the database and query connections
Set db = CurrentDb()
Set MailList = db.OpenRecordset("MyEmailAddresses")
ingrscount = MailList.RecordCount
If ingrscount = 0 Then
MsgBox ("Geen e-mail adres beschikbaar in MyEmailAddresses")
Else
MailList.MoveLast
MailList.MoveFirst
Do Until MailList.EOF
ingcount = ingcount + 1
Subjectline$ = "Automatische e-mail :: Overzicht uren - TIVA [" & MailList.Fields("Naam") & "]"
BodyFile$ = "Z:\mailbody.txt"
Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
MyBody.Close
Form_F_admin.mailnumber.Value = MailList.Fields("Technr")
'BIJLAGE
Dim MyPath As String
Dim MyFilename As String
MyPath = "H:\19.TIVA\Detailuren\"
MyFilename = Format(Form_F_admin.vandat, "dd") & _
"-" & Format(Form_F_admin.vandat, "mm") & "-" & Format(Form_F_admin.vandat, "yyyy") & _
" tot " & Format(Form_F_admin.totdatum, "dd") & _
"-" & Format(Form_F_admin.totdatum, "mm") & "-" & Format(Form_F_admin.totdatum, "yyyy") & _
"-" & MailList.Fields("Naam") & ".pdf"
DoCmd.OpenReport "R_SENDMAIL", acViewPreview
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & MyFilename, True
'Let's close our previewed report
DoCmd.Close acReport, "R_SENDMAIL"
'kill pdf preview
Dim sKillWord As String
sKillWord = "TASKKILL /F /IM AcroRd32.exe"
Shell sKillWord, vbHide
MyMail.Attachments.Add MyPath & MyFilename, olByValue, 1, "Uren TIVA"
'EINDE BIJLAGE
Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = MailList("email")
MyMail.Subject = Subjectline$
MyMail.Body = MyBodyText
MyMail.Send
MailList.MoveNext
Loop
'Cleanup
Set MyMail = Nothing
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End If
Weet iemand hoe ik die melding weg krijgen en dus mijn bijlage (bestand op pc) kan meesturen.