Boomkweker
Gebruiker
- Lid geworden
- 17 nov 2016
- Berichten
- 25
Oke ik hoop dat het nu lukt dan. Om een daglijst te genereren in het Rapport Verzendlijst2 moet je even de datum 16-01-16 gebruiken. Voor rekeningen versturen gebruik ik de module Rekeningen sturen. Wat ik verder wens heb ik in het vorige bericht hopelijk zo goed mogelijk beschreven
Nu zou ik willen dat er op een gegeven moment, bij voorkeur dagelijks om 17uur een lijst komt van klanten die op die dag een levering hebben gehad en daar vervolgens de verzendlijst van die betreffende dag naar de desbetreffende klant wordt gestuurd. Met de hulp van NoellaG krijg ik nu een lijst met hierin de velden
[OrderId] [KlantID] [Leverdatum] [Naam Klant] [Mailadres Klant].
[2185] [600061] [19-3-2020] [Groen Direkt] [GD@GD.NL]
Kan ik nu op basis van deze gegevens automatisch(of wanneer het niet anders kan op klik) het rapport Verzendlijst openen voor Groen Direkt van datum 19-3-2020 en dit gelijk als pdf bijlage versturen naar GD@GD.NL
Code:
Public Function SendInvoice()
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 fso As FileSystemObject
Dim strRptName As String
Set fso = New FileSystemObject
strRptName = "DigitaleFactuur"
Set MyOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("DigitaalFactureren")
Do Until MailList.EOF
' Here we open the report with Invoicenumber of the maillist
' Afther that we save it in our Invoice folder
DoCmd.OpenReport "DigitaleFactuur", acViewPreview, , "Factuurnummer = " & MailList!Factuurnummer
DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, "O:\backup\AJ de Lange\Jaaroverzichten\DigitaleFacturen\" & MailList!Factuurnummer & ".pdf"
'We check if there is a mailadres for Invoices when yes then send when no then print out
If Len(MailList("Factuurmailadres") & vbNullString) = 0 Then
DoCmd.OpenReport "DigitaleFactuur", , , "Factuurnummer = " & MailList!Factuurnummer
Else
'We're going to prepair the mail
Set MyMail = MyOutlook.CreateItemFromTemplate("C:\Users\Gebruiker\AppData\Roaming\Microsoft\Templates\Digitale factuur.oft")
' This addresses it
MyMail.To = MailList("Factuurmailadres")
MyMail.BCC = MailList("Webadres")
'This gives it a subject
MyMail.Subject = "Factuur " & MailList!Ordermaand & " Boomkwekerij de Lange"
'Here we attach the invoice to the mailadress
MyMail.Attachments.Add "O:\backup\AJ de Lange\Jaaroverzichten\DigitaleFacturen\" & MailList!Factuurnummer & ".pdf", olByValue, 1, "My Displayname"
' "My Displayname" = If you don??t want the attachment??s icon string to be "c:myfile.txt" you
' can use this property to change it to something useful, i.e. "4th Qtr Report"
'This display it ready to send, i like to check if invoice is wright!
MyMail.Display
End If
DoCmd.Close acReport, strRptName, acSaveNo
'And on to the next one...
MailList.MoveNext
Loop
'Cleanup after ourselves
Set MyMail = Nothing
'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.
'MyOutlook.Quit
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End Function