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

    Code doesn't open outlook and it should

    Hello,



    So far, I am succesfully using this code to send emails via Outlook

    Code:
    Public Sub EnviarEmail(strEmail As String, strAsunto As String, srtCuerpoEmail As String, Optional strAdjunto As String)
     Dim olApp As Object
     Dim objMail As Object
     Dim aArchivosAdjuntos() As String
    
    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
     If Not IsNull(strAdjunto) Then
            aArchivosAdjuntos = Split(strAdjunto, ";")
            For i = LBound(aArchivosAdjuntos) To UBound(aArchivosAdjuntos)
                .Attachments.Add aArchivosAdjuntos(i), olByValue, , "My Displayname"
            Next i
     End If
     .Send
    
    DoEvents
    
     End With
     
    Set olApp = Nothing
    Set objMail = Nothing
    
     MsgBox "Email enviado con éxito"
     
     End Sub
    When I introduced it, it was in another computer and worked fine. In the PC I am currently using my program, it only works if I manually open Outlook. Then it sends all the emails in the queue. As I understand the code, it is supposed to be able to launch the program. Could it be that is beeing blocked?

    Another question. This code gives a sort of confirmation when it finishes. This confirmation is totally virtual. Is there anyway to get an actual confirmation from outlook that the email is really sent?

    Thank you very much.

  2. #2
    vincent-leeway is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    36
    Have you set up the mail server in your new PC?

  3. #3
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by vincent-leeway View Post
    Have you set up the mail server in your new PC?
    Of course. As I said before, code works great if I manually open outlook first.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    It seems like your error trapping may be skipping over something, not sure though. Have you tried stepping through each line?

    I use a function by Dev Ashish to make sure I have Outlook running on XP. http://access.mvps.org/access/api/api0007.htm

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Should be a document in your Sent folder. Code can probably verify that the email is there.
    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.

  6. #6
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by June7 View Post
    Should be a document in your Sent folder. Code can probably verify that the email is there.
    How would you do that?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I don't have code to accomplish that, I just know it should be possible.

    Bing: Access vba Outlook find message sent folder

    This thread has code sample for cycling through messages of folder, maybe it can be tailored for the Sent folder http://windowssecrets.com/forums/sho...k-mail-folders
    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.

  8. #8
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    I finally solved it by changing the variable declaration of the objects:

    Code:
    Dim olApp As Outlook.Application
     Dim objMail As Outlook.MailItem
    I couldn't solve the "confirmation" point though.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Here is better reference for code to access items in Outlook mail folders. http://www.freevbcode.com/ShowCode.asp?ID=4837

    Works great. I didn't have to modify at all.
    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.

  10. #10
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Not solved at all...

    This is weird. If I finish with ".Send" it works. But if I use ".Display" to preview, it opens Outlook and when I press "send" in the genuine Outlook window, the window closes but it does not send the mail!! I have to open Outlook manually to proceed to the upload.

    I need a code that keeps Outlook running in background.

    Quote Originally Posted by June7 View Post
    Here is better reference for code to access items in Outlook mail folders. http://www.freevbcode.com/ShowCode.asp?ID=4837

    Works great. I didn't have to modify at all.
    I'll check this, thanks!

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I tested your code. I commented the attachment part and eliminated the variables and used literal text. I set it for .Display. The code works even with Outlook closed, however, I get the Outlook username/password dialogue.
    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.

  12. #12
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by June7 View Post
    I tested your code. I commented the attachment part and eliminated the variables and used literal text. I set it for .Display. The code works even with Outlook closed, however, I get the Outlook username/password dialogue.
    I tried it in two different PCs so I don't know what to say. Perhaps you have somehow Outlook executing on the background.

    Perhaps is something in my database -my access- that is making all the trouble...

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    If Outlook is in the 'background' I don't know how.

    Might be something in Tools > Trust Center need to change. I have Programmatic Access Security set to 'Never warn me ...' but if you are able to .Send the message then I suppose this is already set.

    Sorry, can't replicate the issue.
    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.

  14. #14
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Is there any code to launch Outlook's main form, just like I had double-clicked the icon??

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Try:

    Shell SysCmd(acSysCmdAccessDir) & "Outlook.exe"
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. My query code doesn't work
    By blacksaibot in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 02:59 PM
  2. Replies: 1
    Last Post: 12-20-2011, 08:15 PM
  3. Menu doesn't open after TransferDatabase
    By ghillie30 in forum Access
    Replies: 6
    Last Post: 10-27-2011, 06:56 AM
  4. Form doesn't open in Dialog mode
    By accessnewb in forum Programming
    Replies: 3
    Last Post: 08-02-2011, 08:38 AM
  5. Replies: 3
    Last Post: 12-09-2010, 11:50 AM

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