reneemettrie
Terugkerende gebruiker
- Lid geworden
- 1 aug 2006
- Berichten
- 1.233
Ik heb 2 mailaccounts in Outlook, van het werk en privé. Privé=default. Nu wil ik een mailing doen voor een sportclub, dus privé. Maar de volgende code genereert de mails met de werk-account. Is natuurlijk niet de bedoeling. Hoe los ik dit op?(heb geen ervaring met VBA Outlook, dit deel van de code gezocht op Internet).
Code:
Private Sub MailAll()
Dim db As DAO.Database, rs As DAO.Recordset
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim Message As String, Subject As String, Destination As String
On Error GoTo MyError
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Mails")
Set OutApp = New Outlook.Application
OutApp.Session.Logon
Do Until rs.EOF
Set OutMail = OutApp.CreateItem(olMailItem)
Message = "Sportieve groeten en een fijn mushing seizoen!" & vbNewLine _
& "Salutations sportives et une excellente saison mushing! " & vbNewLine _
& vbNewLine _
& "Renée Mettrie" & vbNewLine _
& "Secretaris MBEL"
Subject = "AV/AG MBEL 2/7/2022"
With OutMail
Destination = Left(rs!Mail, InStr(rs!Mail, "#") - 1) 'Instr finds the position of the string "#" in the field "Mail"
.To = Destination
.Subject = Subject
.Body = Message
.Attachments.Add CurrentProject.Path & "\AV-AG 2022 NL FR.docx"
'.Display
.Send
Debug.Print rs!ID
End With
rs.MoveNext
Loop
Set OutMail = Nothing
Set OutApp = Nothing
MsgBox "Finished"
Exit Sub
MyError:
MsgBox Err.Description
End Sub