Results 1 to 8 of 8
  1. #1
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31

    Read email addresses from subform and creat a new mail

    Hi there,

    I can't seem to find an answer to this problem anywhere:

    I have a main form "Daten" with a subform "BewerberUF". The sub form is formatted as a table and contains 11 columns. The column titled "NachVor" contains the surname and the first name of customers divieded by a comma (eg. Smith, John). How can I loop through the records in the subform, extract the data in the fields "NachVor", open Outlook, create a new message and insert all the data from NachVor into the "From" Field on the new mail?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Code:
    'collect all the emails in the subform
    sub btnSendEmails_click()
    dim vTo
    
    with me.subform.form.recordset
        .movefirst
        while not .eof
            vTo = vTo & ";"
           .movenext
        wend
    
         'send email
       email1 vTo, "subject mater" , "body of email"
    end sub
    
    
    Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    '-------
    'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark MICROSOFT OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References
    '-------
    
    On Error GoTo ErrMail
    
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(olMailItem)
    
    With oMail
        .To = pvTo
        .Subject = pvSubj
        .Body = pvBody
        
        .Send
    End With
    Email1=true
    
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    
    
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume Next
    End Function

  3. #3
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31
    Thanks for the quick help. Unfortunately I am getting the following error at the word "subform" in the line with me.subform.form.recordset

    Compile Error - Method or Data member not Found

    What am I doing wrong?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ranman appears to be offline. Replace "subform" with the name of your subform control ("BewerberUF" ?). The name of the control on the main form, not the name of the subform itself if they're different.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31
    I can now get the Code to run through. I can see that it is running through the subform table but it is not returning any values. If I Output the read values to a message box I just get a whole line of semi colons. Access Returns an error saying that no recipients were specified. Any ideas?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ranman forgot the email address. Try adding:

    vTo = vTo & !EmailAddressFieldName & ";"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31
    That is fantastic. Thank you so much

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. Ranman did all the heavy lifting.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 7
    Last Post: 08-01-2017, 06:38 PM
  2. Replies: 3
    Last Post: 05-07-2015, 08:56 PM
  3. Parsing e-mail addresses
    By SgtSaunders69 in forum Queries
    Replies: 4
    Last Post: 01-15-2015, 03:07 PM
  4. Replies: 2
    Last Post: 12-13-2013, 03:13 PM
  5. VBA to Send E-mail to Addresses from Query
    By alpinegroove in forum Programming
    Replies: 4
    Last Post: 12-23-2011, 09:45 AM

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