Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to send Outlook emails from Access 7

Status
Not open for further replies.

gazolba

Programmer
Dec 4, 2001
167
0
0
US
Where can I find the code to send Outlook emails from Access. I need to be able to set the 'importance flag' and need to be able to control the 'from' and 'to' emails. I need an example that emails to multiple addresses. Have not been able to find this anywhere. Hope someone can help.
MS Access help is useless. I'm using Access 2000.
 
Star for you PHV! Thanks so much! By using the .display function the security warning no longer displays (I assume because it's the user who actually then requests that the message be sent, rather than an automated program.)

For interested parties this also works with the 'Outlook.AppointmentItem' as well.

Will be interested in learning the answer to maxhugen's question.
 
What is the code to see if Outlook is open or not? I have found that running my Access code when Outlook is closed causes errors.

Thanks,

Seth Dromgoole
 
What is the code to see if Outlook is open or not?
On Error Resume Next
Set myOL = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "Warning, Outlook is NOT open"
End If
On Error GoTo 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
i use this function to send mail
Code:
Sub SendEmail(ByVal sTo As String, ByVal sSubject As String, ByVal sBody As String, Optional sFile As String, Optional sBlind As String)

    On Error GoTo EH_SendEmail
    
    Dim oApp As Outlook.Application
    Dim sEmail As String
    Dim iPos As Integer
    Dim i As Integer
    Dim iCount As Integer
    Dim oMailItem As Outlook.MailItem
    Dim oReceipt As Outlook.Recipient
    Dim oAttach As Outlook.Attachment '- use to attach a file
    
    'open Outlook
    Set oApp = CreateObject("Outlook.Application")
       
    'Create mail message
    Set oMailItem = oApp.CreateItem(olMailItem)
    
    With oMailItem
        Set oReceipt = .Recipients.Add(sTo)
        oReceipt.Type = olTo
        .Subject = sSubject
        .Body = sBody
        'if Blind Copy needed
        If Not IsNull(sBlind) And sBlind <> "" Then
            .BCC = sBlind
        End If
         'use to attach a file at sFile
        If Not IsNull(sFile) And sFile <> "" Then
            Set oAttach = .Attachments.Add(sFile)
        End If
        'send to outlook outbox
        .Send
    End With
        
    Set oReceipt = Nothing
    Set oAttach = Nothing
    Set oMailItem = Nothing
        
    Set oApp = Nothing

    Exit Sub
EH_SendEmail:
    MsgBox "Error in EH_SendEmail " & Error(Err) & " " & CStr(Err)
    Resume Next
End Sub

it also handles attachments
 
1DMF - would this work to send separate emails to different recipients each with their own personalized Access report as an attachment?
 
Very good thread! Anyone goty a simple solution to get around the Security that Outlook fires off, when attempting to use this code under Outlook-2003? I get a prompt basically saying An application is attempting to send an email on my behalf. Press Ok to Send, or No... I remember reading about a ClickYes or Redemption library to get around this... any other ideas/clues... tia,

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Do a google search for outlook object model guard

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
dtay1132 - yes, but you would need to write the routine caling this function looping the email email recipients and passing the attachment to be sent with it.

to add an attachment you pass the above function the value for sFile.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Already looked at ClickYes and Redemption... Wanted to avoid any 3rd party tools if at all possible...

My actual solution was to use XP_SendMail... under SQL Server.... Eliminates the popup issue all together...

thanks,

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Glad you found a solution, does that leave a copy in a sent items folder for history/compliance purposes.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top