Results 1 to 2 of 2
  1. #1
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91

    Problem sending email with Outlook via VBA (it duplicates)

    I have made a form to send emails, I used this code I found somewhere:
    Code:
    Private Sub cmdEnviarOutlook_Click()
    
    Call EnviarEmail(Me.txtEmail, Me.txtAsuntoEmail, Me.txtLeyenda)
    
    End Sub
    Code:
    Public Sub EnviarEmail(strEmail As String, strAsunto As String, srtCuerpoEmail As String)
     Dim olApp As Object
     Dim objMail As Object
    
     On Error Resume Next 'Keep going if there is an error
    
    
     Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
    
    
     If Err Then 'Outlook is not open
     Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
     End If
    
     'Create e-mail item
     Set objMail = olApp.CreateItem(olMailItem)
    
     With objMail
    
     'Set body format to HTML
     .BodyFormat = olFormatHTML
     .To = strEmail
     .Subject = strAsunto
     .HTMLBody = srtCuerpoEmail
     .Send
    
     End With
    
    Set olApp = Nothing
    Set objMail = Nothing
    
     MsgBox "Email enviado con éxito"
     
     End Sub
    I configured Outlook with my gmail account.

    The code works fine (after adding references) but when I take a look to the sent-box in Gmail, I find that the email is duplicated.


    Why is this happening?

    If I send an email normally or even using docmd.sendobject, that doesn't happen.

    One more question. I tried this function in two computers and in one of them Outlook asks for permission while it does not in the other one. I believe it is related with Outlook config. Where can I change this??

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    No idea why the duplicate email - doesn't happen with me using Outlook Exchange or Hotmail.

    Check out the Outlook option settings: File > Options > Programmatic Access
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 03-12-2013, 11:49 AM
  2. sending data into an email body - outlook
    By webisti in forum Access
    Replies: 6
    Last Post: 02-15-2012, 07:05 AM
  3. Replies: 3
    Last Post: 09-01-2010, 08:43 PM
  4. Replies: 1
    Last Post: 03-09-2006, 01:50 PM
  5. Sending email via Outlook (and Exchange2003) from Access2003
    By Larry Elfenbein in forum Programming
    Replies: 0
    Last Post: 11-15-2005, 09:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums