Page 3 of 3 FirstFirst 123
Results 31 to 43 of 43
  1. #31
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Wait !! I closed the DB and went back in. I now see emails in the Immediate. I still get the runtime error but we're making progress.

  2. #32
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Change the last line to:
    Code:
    DoCmd.SendObject acSendNoObject, , , sEmails, , , , , , True
    You should now get a new Outlook message with the Bcc line populated. Examine the list for any bad email.

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

  3. #33
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Also change this line:

    Code:
    sEmails = Left(sEmails, Len(sEmails) - 1) 'trim the last comma
    to:
    Code:
    sEmails = Trim(Left(sEmails, Len(sEmails) - 1)) 'trim the last comma and any leading or ending spaces
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #34
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Also you must ensure that you're query is not including any records without an email address, add Is Not Null in the criteria row of the [Email] field in the source query.

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

  5. #35
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think this updated code would work and it is more flexible as it allows you to attach external files as attachments if needed.
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Command0_Click()
    
    
    Dim sEmails As String
    Dim qdf As QueryDef, prm As Parameter, rst As DAO.Recordset
    
    
    Set qdf = CurrentDb.QueryDefs("Q_All_Emails_no_dups")
    For Each prm In qdf.Parameters
    	prm.Value = Eval(prm.Name)
    Next prm
    
    
    Set rst = qdf.OpenRecordset
    
    
    Set rst = CurrentDb.OpenRecordset("Q_All_Emails_no_dups")
    sEmails = ""
    Do Until rst.EOF
    	If Not IsNull(rst("[Email]")) then sEmails = sEmails & rst("[Email]") & ";"
    rst.movenext
    Loop
    
    
    sEmails = Trim(Left(sEmails, Len(sEmails) - 1)) 'trim the last semi-colon and any leading and trailing spaces
    
    
    'Debug.Print sEmails
    'DoCmd.SendObject acSendNoObject, , , , , sEmails, , , , False
    'use Outlook autmotation instead of SendObject
    Call vcSendEmail_Outlook_With_Attachment ("Test email bCC","","",sEmails,"","Please review this test email")
    End Sub
    
    
    
    
    
    
    Function vcSendEmail_Outlook_With_Attachment(sSubject As String, sTo As String, Optional sCC As String, Optional sBcc As String, Optional sAttachment As String, Optional sBody As String)
        Dim OutApp As Object
        Dim OutMail As Object
     
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon 
       
        Set OutMail = OutApp.CreateItem(0)
     
        OutMail.To = sTo
        If sCC <> "" Then OutMail.CC = sCC
        If sBcc <> "" Then OutMail.BCC = sBcc
        OutMail.Subject = sSubject
        If sBody <> "" Then OutMail.HTMLBody = sBody  
    
    
        If sAttachment <> "" Then OutMail.Attachments.Add (sAttachment)
    
    
        OutMail.Display  'Send | Display
    '    OutMail.Inspector.Activate
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Function
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #36
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Good morning, Here I am again.

    I didn't add your extra script. I want to get the first part working. Here is what I have but I am getting a compile error on acSendNoObject. I have tried it with the true and false.

    Option Compare Database
    Option Explicit




    Private Sub Command0_Click()
    Dim sEmails As String
    Dim qdf As QueryDef, prm As Parameter, rst As DAO.Recordset
    Set qdf = CurrentDb.QueryDefs("Q_All_Emails_no_dups")
    For Each prm In qdf.Parameters
    prm.Value = Eval(prm.Name)
    Next prm




    Set rst = qdf.OpenRecordset




    Set rst = CurrentDb.OpenRecordset("Q_All_Emails_no_dups")
    sEmails = ""
    Do Until rst.EOF
    If Not IsNull(rst("[Email]")) Then sEmails = sEmails & rst("[Email]") & ";"
    rst.movenext
    Loop


    sEmails = Trim(Left(sEmails, Len(sEmails) - 1)) 'trim the last semi-colon and any leading and trailing spaces




    Debug.Print sEmails
    DoCmd.SendObject acSendNoObject, , , , , sEmails, , , , True

  7. #37
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Fixed that. Getting the Runtime error 2295 on the DoCmd.SendObject acSendNoObject,,,,,sEmails,,,,True

  8. #38
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    In the Immediate screen the emails have carriage returns, it's not one long string. Could that be the problem? How do we get the carriage return out?

  9. #39
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Are the emails stored with in the table with carriage returns? How are they entered? You can try to use replace to remove them:

    Code:
    sEmails = Trim(Left(sEmails, Len(sEmails) - 1)) 'trim the last semi-colon and any leading and trailing spaces
    sEmails=Replace(sEmails,vbCrLn,"")
    My other script was not an addition but a replacement, replacing one method of emailing (Docmd.SendObject) with another (Outlook Automation).

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

  10. #40
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Welcome back to my nightmare

    Here is what I have. It is giving a run-time error 2482 Microsoft Access cannot find the name 'Tbl_DO_Stakeholder_data' you entered in the expression. It highlights the prm.Value =Eval(prm.Name) section

    Option Compare Database
    Option Explicit




    Private Sub Command0_Click()




    Dim sEmails As String
    Dim qdf As QueryDef, prm As Parameter, rst As DAO.Recordset




    Set qdf = CurrentDb.QueryDefs("Q_All_Emails_no_dups")
    For Each prm In qdf.Parameters
    prm.Value = Eval(prm.Name)
    Next prm




    Set rst = qdf.OpenRecordset




    Set rst = CurrentDb.OpenRecordset("Q_All_Emails_no_dups")
    sEmails = ""
    Do Until rst.EOF
    If Not IsNull(rst("[Email]")) Then sEmails = sEmails & rst("[Email]") & ";"
    rst.movenext
    Loop




    sEmails = Trim(Left(sEmails, Len(sEmails) - 1)) 'trim the last semi-colon and any leading and trailing spaces
    sEmails = Replace(sEmails, vbCrLf, "")




    'Debug.Print sEmails
    'DoCmd.SendObject acSendNoObject, , , , , sEmails, , , , False
    'use Outlook autmotation instead of SendObject
    Call vcSendEmail_Outlook_With_Attachment("Test email bCC", "", "", sEmails, "", "Please review this test email")
    End Sub












    Function vcSendEmail_Outlook_With_Attachment(sSubject As String, sTo As String, Optional sCC As String, Optional sBcc As String, Optional sAttachment As String, Optional sBody As String)
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon

    Set OutMail = OutApp.CreateItem(0)

    OutMail.To = sTo
    If sCC <> "" Then OutMail.CC = sCC
    If sBcc <> "" Then OutMail.BCC = sBcc
    OutMail.Subject = sSubject
    If sBody <> "" Then OutMail.HTMLBody = sBody




    If sAttachment <> "" Then OutMail.Attachments.Add (sAttachment)




    OutMail.Display 'Send | Display
    ' OutMail.Inspector.Activate
    Set OutMail = Nothing
    Set OutApp = Nothing
    End Function

  11. #41
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    OH! IT Worked...everything looks great!!!!! Thank you, thank you, thank you!

  12. #42
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you show the query? Is that a parameter in it?
    The best at this point would be if you could start with a new Access file, import the table having the email field (Tbl_DO_Stakeholder_data), the query (Q_All_Emails_no_dups) in which you renamed the PCO_Email to Email and the form where you want to do the emailing. Remove all but a couple of records from the table and make sure there is no sensitive data. Compact the new file, zip it and upload it here (at the top of the forum page there is info how to attach files).

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

  13. #43
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Using Docmd.SendObject or Outlook automation? In any case, great work!
    Good luck with your project !
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-08-2019, 11:03 AM
  2. Add attachments from database to email
    By Vol71 in forum Access
    Replies: 4
    Last Post: 07-21-2015, 11:09 AM
  3. Using query to group attachments for email
    By Monterey_Manzer in forum Access
    Replies: 7
    Last Post: 05-31-2013, 01:37 PM
  4. If and Multiple Email Attachments
    By beckysright in forum Programming
    Replies: 5
    Last Post: 12-13-2012, 03:25 PM
  5. Send email with attachments
    By rbiggs in forum Programming
    Replies: 12
    Last Post: 07-23-2011, 12:50 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