Results 1 to 12 of 12
  1. #1
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136

    Problem sending emails where there are 2 email addresses

    I am not experienced in VB but have received help in the past. One part of the code for sending emails from Access through Outlook that I received in the past is
    strEmail = """" & .Column(1, varItem) & ""
    where the information that is picked up from Column 1 is either simply '***@gmail.com' or '***@Gmail.com; ***@talktalk.net'. This has worked in the past but today where there is only one email address in this field everything works OK but it throws up a problem then there are 2 - the message reads 'Run-time error 2205. Unknown message recipient. the message was not sent'. If I copy the 2 email addresses from the field and paste them into Outlook there is no problem sending an email to both. Has something happened in some download from MS that is causing this problem? Does the wording of the strEmail cause the problem? If so, can it be modified simply to handle either 1 or 2 email addresses?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    Just send 2 separate emails,by looping thru the list.
    access doesn't care how many it sends.

  3. #3
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Unfortunately I didn't provide sufficient information in my original post to help you to fully understand the problem!

    We have a large number of organisations that we write to and some of these want us to send our emails to 2 particular addressees. So the programme scrolls through each of the organisations and then picks up the email addresses from the Email field. It is that field that can contain either 1 or 2 email addresses. So the strEmail line in the code picks up the email addresses and the rest of the code sends the emails.

    I trust this helps you to understand the original question.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Put a 'Debug.Print strEmail' in the code just after setting the value. It will show you what is being passed in the TO: field.
    After we see the format when trying to send more than one, we can see how to adjust code for 2 addresses.
    Last edited by davegri; 12-09-2016 at 10:47 AM. Reason: clarity

  5. #5
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    I have done as you suggest, and my 2 lines of code now are as follows -
    strEmail = """" & .Column(1, varItem) & ""
    Debug.Print strEmail
    Is it supposed to stop at that point and show the value of strEmail? It just sails on to the end of the code! Where should I look for the value of strEmail?

  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
    Here's a picture of where to see it:

    BaldyWeb-Immediate window
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    That should be very helpful, pbaldy. But when I look at my VB code I can't see anything like your 'Immediate' section. As you will appreciate I am not very familiar with Visual basic so is there something that I still need to do to replicate what you have demonstrated in your link? Sorry to be a nuisance!

  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
    In the VBA editor, click on View/Immediate Window, or Ctrl-G.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Brilliant!! What it shows is "***@gmail.com; ***@talktalk.net. There is " in front of the first email address and nothing at the end. This seems to be the same as when there is only one email address in the field. Does this throw any light on why it won't send the 2 emails? Because a single email address is sent OK.

  10. #10
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    strEmail = .Column(1, varItem)
    Try above. I don't see any need for the apostrophes. It's already a valid string.

  11. #11
    Baldeagle is offline Competent Performer
    Windows 10 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Thanks for that advice. I have used your amended code and it works!! I appreciate your assistance. All I need now is help on the query that I put into the Outlook forum at the same time because I am getting this message - 'A programme is trying to send an email message on your behalf....' and the operator in Access has to click on 'Allow' for every individual email. If you can help on that in the MS Office (Outlook) forum that would complete my problems for the present.

    In the meantime I will mark this thread as Solved with thanks to everyone who has contributed.

  12. #12
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Others can advise you at the Outlook forum, where that expertise lies.
    Glad we could help here.

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

Similar Threads

  1. Sending emails without interruptions
    By George in forum Access
    Replies: 14
    Last Post: 03-13-2015, 11:15 PM
  2. sending multiple emails wth vba
    By baronqueefington in forum Programming
    Replies: 2
    Last Post: 02-09-2015, 02:49 PM
  3. Sending Emails and VBA coding
    By lucy1216 in forum Programming
    Replies: 4
    Last Post: 05-20-2013, 05:57 AM
  4. Replies: 1
    Last Post: 05-05-2013, 12:13 PM
  5. Replies: 1
    Last Post: 11-14-2012, 01:43 PM

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