Results 1 to 7 of 7
  1. #1
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32

    Access email completes but does not send

    I have an app that sends email to the recipients listed in a list box It is only a subject and an attached letter. I have used it in the past with good success. I have only changed the word document name both in the email code and in the table feeding the list box. I go through the code and I get the response that x messages have been sent, but the emails never arrive. Maybe somebody can see something that i have missed. Does it matter if the doc is doc or docs or pdf? Code follows:





    Private Sub CmdEmail_Click()
    MsgBox "This may take a few minutes, press OK to continue"
    Dim i As Integer
    Dim RowCnt As Integer
    RowCnt = LstEmail.ListCount
    TaleyOf = RowCnt
    For i = 0 To RowCnt
    Me.EmailAddress = LstEmail.Column(2, i)
    'Send email
    Dim wd As Object 'Word.Application
    Dim doc As Object 'Word.Document
    Dim itm As Object 'Outlook.MailItem
    Dim ID As String
    Dim blnWeOpenedWord As Boolean
    On Error Resume Next
    Set wd = CreateObject("Word.Application")
    blnWeOpenedWord = True
    Set doc = wd.Documents.Open _
    (FileName:="E:\Paradise\ParadiseGuestEmail.doc", ReadOnly:=True)
    Set itm = doc.MailEnvelope.Item

    With itm
    .To = Me.EmailAddress
    .Subject = "Paradise Vacation Resorts"
    .Send
    Tally = i + 1
    End With

    doc.Close 0 'wdDoNotSaveChanges
    If blnWeOpenedWord Then
    wd.Quit
    End If
    Next
    MsgBox i - 1 & " Messages have been sent"
    DoCmd.Close

    End Sub

    Any help appreciated

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,007
    Well you can start by putting
    Option Explicit
    at the top of every module and Require Variable Declaration in VBA window Tools/Options as you have undeclared variables.

    Code:
    On Error Resume Next
    is not doing you any favours?, you should have error checking.

    After correcting all those, that code does absolutely nothing for me?
    Commenting out the error line I get
    'The requested operation requires elevation'

    I just use Outlook mailitem. never seen your code method before, but if it worked before?, what has changed.?

    Comment out the error line, fix the missing variables and walk through the code line by line with F8 and see what it actually does, not what you think it does.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    the SEND just puts the mail in OUTBOX pending the next send/Receive event.
    you can do it manually with the toolbar button,
    or
    i think this command does it:
    Public WithEvents mySync As Outlook.SyncObject
    ThisOutlookSession.mySync.Start

  4. #4
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    Thanks for the suggestions. I will see where it goes.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    Please try this updated code and see what error you get (if any):
    Code:
    Option Explicit
    'ADD ABOVE LINE AT THE TOP OF THE MODULE THEN COMPILE
    
    
    Private Sub CmdEmail_Click()
    Dim i As Integer
    Dim RowCnt As Integer
    Dim wd As Object 'Word.Application
    Dim doc As Object 'Word.Document
    Dim itm As Object 'Outlook.MailItem
    Dim ID As String
    Dim blnWeOpenedWord As Boolean
    Dim sEmailAddress 'new variable
    
    
    MsgBox "This may take a few minutes, press OK to continue"
    
    
    RowCnt = Me.LstEmail.ListCount
    'TaleyOf = RowCnt  'NOT USED AND NOT DECLARED
    
    
    For i = 0 To RowCnt
        'Me.EmailAddress = LstEmail.Column(2, i)
        sEmailAddress=Me.LstEmail.Column(2, i)
        'Send email
        'On Error Resume Next 'THIS LINE STOPS THE ERROR
        Set wd = CreateObject("Word.Application")
        blnWeOpenedWord = True
        Set doc = wd.Documents.Open _
        (FileName:="E:\Paradise\ParadiseGuestEmail.doc", ReadOnly:=True) 'ARE YOU SURE IT IS .DOC AND NOT .DOCX?
        Set itm = doc.MailEnvelope.Item
    
    
        With itm
            .To = sEmailAddress 'better than constantly updating the form with Me.EmailAddress
            .Subject = "Paradise Vacation Resorts"
            .Send
            'Tally = i + 1 'NOT USED AND NOT DECLARED
        End With
    
    
        doc.Close 0 'wdDoNotSaveChanges
        If blnWeOpenedWord Then
            wd.Quit
        End If
    Next
    MsgBox i - 1 & " Messages have been sent"
    'Are you closing the form, if yes use something like this
    Docmd.Close asForm, Me.Name
    'DoCmd.Close 
    End Sub
    EDIT: Just saw Welshgasman's post
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    Thanks Gicu. I'm up and running. I will give the new code a shot later.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    You mean it is now working without any changes? The code I posted is not really "new" just an modified version of yours to address some of the issues (see code comments).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 4
    Last Post: 07-12-2018, 05:38 AM
  2. Replies: 5
    Last Post: 05-07-2014, 09:25 AM
  3. how to send email in access 2010
    By nickblitz in forum Access
    Replies: 3
    Last Post: 10-29-2012, 07:28 AM
  4. How can I send an email from access???
    By Asma in forum Programming
    Replies: 2
    Last Post: 12-07-2011, 07:49 AM
  5. VBA to Send email from Access
    By ped in forum Access
    Replies: 3
    Last Post: 08-11-2011, 05:37 PM

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