Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking with Outlook using MS Access 2003 - VBA
    primarykey
    data
    text
    <p>I've made the following program that takes a list of email addresses from a table in MS Access and sends each a test email. Here is the code:</p> <pre><code>'Get data back from field birth date Set fld = rcdSet.Fields("Email Address") 'Subject olMailItem.Subject = "Mailing List Test" 'Loop through the records For i = 0 To intNumRecords 'Recipient/s olMailItem.To = fld.Value 'Body of email olMailItem.Body = strBodyText 'Automatically send the email olMailItem.Send 'Reset email item otherwise it won't work Set olMailItem = olFolder.Items.Add("IPM.Note") 'Move to the next record rcdSet.MoveNext Next </code></pre> <p>And yes I opened a record set but haven't included that code above. So here's my questions:</p> <ol> <li><p>Is my approach above correct? I had to reset the <code>olMailItem</code> in the loop otherwise it would return a <code>Type Error</code>. Is there a better approach to sending multiple emails?</p></li> <li><p>I put in an invalid email to see what happens - it causes another <code>Type Error</code>. Is there anyway to detect the bounce back (the email outlook sends to you informing you that it was a bad address) email and send a message to the <code>Immediate Window</code> (For dev purposes at this point)</p></li> </ol> <p>Thanks</p> <p>Note - Have added declaration of mail items </p> <pre><code>'Create Outlook object Dim olApp As Outlook.Application 'Namespace Dim olNS As Outlook.NameSpace Dim olFolder As Outlook.MAPIFolder 'Create a reference to the email item you will use to send the email Dim olMailItem As Outlook.MailItem Set olApp = CreateObject("Outlook.Application") Set olNS = olApp.GetNamespace("MAPI") Set olFolder = olNS.GetDefaultFolder(olFolderInbox) Set olMailItem = olFolder.Items.Add("IPM.Note") </code></pre> <p>If I don't re-set the olMailItem in the for loop an error occurs on the <code>.To</code> part of the program - the aforementioned <code>Type Error</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload