ksor
03-01-2018, 05:01 AM
As a part of an Access DB I have a button on several forms where the user can click to send a file handled in each of these forms.
I used this code and it work nicely - this code is used an ALL forms when the mail.button is present:
Public Sub sendMail(Attach As String, txt As String)
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
If Attach <> "" Or txt <> "" Then
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatHTML ' olFormatRichText
.To = ""
.cc = ""
'.bcc = ""
.Subject = "Dokument fra Keld Sørensen"
If txt <> "" Then
.Body = txt ' ellers laver den ikke linieskifte med crLf(1) !!!!!!!!!!
' .HTMLBody = txt
Else
.HTMLBody = "Indtast en besked her !"
End If
If Attach <> "" Then .Attachments.add (Attach)
' .Send ' if you want to send without editing
.Display ' showing the mail for editing BEFORE you send it manually
End With
Else
MsgBox "Du vil ikke skrive tekst, du vil ikke vedhæfte noget !!" & CrLf(2) & _
"Hvad vil du egentlig ... Ret fejlen og prøv igen !"
End If
End Sub
But often several files has to be send to the same person from several different forms in my DB - each with that "Mail"-button to click.
How can I change the code to just attaching the files IF the mailitem is already created ?
I used this code and it work nicely - this code is used an ALL forms when the mail.button is present:
Public Sub sendMail(Attach As String, txt As String)
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
If Attach <> "" Or txt <> "" Then
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatHTML ' olFormatRichText
.To = ""
.cc = ""
'.bcc = ""
.Subject = "Dokument fra Keld Sørensen"
If txt <> "" Then
.Body = txt ' ellers laver den ikke linieskifte med crLf(1) !!!!!!!!!!
' .HTMLBody = txt
Else
.HTMLBody = "Indtast en besked her !"
End If
If Attach <> "" Then .Attachments.add (Attach)
' .Send ' if you want to send without editing
.Display ' showing the mail for editing BEFORE you send it manually
End With
Else
MsgBox "Du vil ikke skrive tekst, du vil ikke vedhæfte noget !!" & CrLf(2) & _
"Hvad vil du egentlig ... Ret fejlen og prøv igen !"
End If
End Sub
But often several files has to be send to the same person from several different forms in my DB - each with that "Mail"-button to click.
How can I change the code to just attaching the files IF the mailitem is already created ?