Hi,
If I use automation to send email with attachment in access, can user select email address from the company global list instead default email address in the code? Below is the code provided by Hans:
Function SendMail( _
Recipient As String, _
Subject As String, _
Message As String, _
Attachment As String) As Boolean
Dim objOL As Outlook.Application
Dim objMI As Outlook.MailItem
Dim blnNotActive As Boolean
Dim intPos1 As Integer, intPos2 As Integer
SysCmd acSysCmdSetStatus, “A moment please. Your e-mail message is being sent.”
DoCmd.Hourglass True
‘ Check whether Outlook is active
On Error Resume Next
Set objOL = GetObject(, “Outlook.Application”)
blnNotActive = (Err 0)
If blnNotActive Then
‘ If not, we start Outlook
Err.Clear
Set objOL = CreateObject(“Outlook.Application”)
End If
On Error GoTo Err_Mail
‘ Create e-mail message
Set objMI = objOL.CreateItem(olMailItem)
With objMI
intPos2 = 1
intPos1 = InStr(intPos2, Recipient, “;”)
Do While intPos1 > 0
.Recipients.Add Mid$(Recipient, intPos2, intPos1 – intPos2)
intPos2 = intPos1 + 1
intPos1 = InStr(intPos2, Recipient, “;”)
Loop
.Recipients.Add Mid$(Recipient, intPos2)
.Subject = Subject
.Body = Message
.Attachments.Add Attachment, olByValue
.Send
End With
SendMail = True
Exit_Mail:
‘ Release object memory
On Error Resume Next
If Not (objMI Is Nothing) Then objMI.Close olDiscard
Set objMI = Nothing
If blnNotActive And Not (objOL Is Nothing) Then objOL.Quit
Set objOL = Nothing
SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Exit Function
Err_Mail:
SendMail = False
Resume Exit_Mail
End Function
Thanks
Regards
Thanks