Page 1 of 3 123 LastLast
Results 1 to 15 of 43
  1. #1
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43

    Email with Bcc only. No attachments

    I know this is a common question but all the threads I read ask about attaching reports and such. I'm sure I am making this more complicated than it needs to be.

    I only want to open an email with the recipients in the Bcc. The data is pulled from the Query Q_All_Emails_no_dups The field name is Email.



    I know it has something to do with the DoCmd.SendObject but I'm sure I am butchering it. That is the only line of code I have. Is there more to it?



    DoCmd.SendObject acSendNoObject, , , [Q_All_Emails_no_dups.Email], , , , , , False

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    BCC is one of the parameters of sendobject

    perhaps explain what you are actually trying to do, it may be that sendobject is not the right thing to be using

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You can't just reference the query and its email field, you need to use a string variable and build a semi-colon or comma delimited list of your email addresses:
    Code:
    Dim sEmails as string
    Dim qdf as DAO.QueryDef, rst as DAO.Recordset
    
    Set qdf=Currentdb.QueryDefs("Q_All_Emails_no_dups")
    Set rst=qdf.openrecordset
    sEmails=""
    Do Until rst.EOF
         sEmails=sEmails & rst("Email") & ","
    rst.movenext
    Loop
    
    sEmails=Left(sEmails,Len(sEmails)-1) 'trim the last comma
    
    DoCmd.SendObject acSendNoObject, , , sEmails, , , , , , False
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Thanks so much. There's no way I would have figured that out.

    It is giving me an error where qdf As DAO.QueryDef, is highlighted.

    ---------------------------Microsoft Visual Basic for Applications
    ---------------------------
    Compile error:


    User-defined type not defined
    ---------------------------
    OK Help
    ---------------------------

  5. #5
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Sorry just use (without the DAO.):
    Code:
    Dim qdf as QueryDef
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Still getting the same area in the same location.

  7. #7
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    I mean "Still getting the same error in the same location

  8. #8
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you please post your code?
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Option Compare Database


    Private Sub Command0_Click()
    Dim sEmails As String
    Dim qdf As QueryDef, rst As Recordset


    Set qdf = CurrentDb.QueryDefs("Q_All_Emails_no_dups")
    Set rst = qdf.openrecordset
    sEmails = ""
    Do Until rst.EOF
    sEmails = sEmails & rst("Email") & ","
    rst.movenext
    Loop


    sEmails = Left(sEmails, Len(sEmails) - 1) 'trim the last comma


    DoCmd.SendObject acSendNoObject, , , sEmails, , , , , , False
    End Sub

  10. #10
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you try:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Command0_Click()
    Dim sEmails as string
    Dim qdf as QueryDef, rst as DAO.Recordset
    
    
    Set qdf=Currentdb.QueryDefs("Q_All_Emails_no_dups")
    Set rst=qdf.openrecordset
    sEmails=""
    Do Until rst.EOF
         sEmails=sEmails & rst("Email") & ","
    rst.movenext
    Loop
    
    
    sEmails=Left(sEmails,Len(sEmails)-1) 'trim the last comma
    
    
    DoCmd.SendObject acSendNoObject, , , sEmails, , , , , , False
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Nope it's just not liking that qdf as QueryDef

  12. #12
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    In the VBE window go to Tools\References and make sure you have checked the Microsoft Office xx.00 Access database engine Object Library where xx is your Office version.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why the need to use a qdf?

    Could you just not use ?
    Code:
    Set rst = CurrentDb.OpenRecordset("Q_All_Emails_no_dups")
    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

  14. #14
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    I went in and checked it. Now it is giving me a Run-time error '2295' Unknow message recipients(s); the message was not sent.

  15. #15
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Of course, I usually use a qdf in case the query has parameters to avoid the "too few parameters...." error.
    Code:
    Dim qdf as QueryDef, prm as Parameter,rst as Dao.Recordset
    Set qdf=Currentdb.QueryDefs("qryMyQuery")
    For each prm in qdf.Parameters
           prm.Value=Eval(prm.Name)
    Next prm
    
    Set rst=qdf.OpenRecordset
    ....
    Didn't include the parameter portion in this post as the query name posted (Q_All_Emails_no_dups) suggested no parameters were used.

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

Page 1 of 3 123 LastLast
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