Results 1 to 9 of 9
  1. #1
    bagwejm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    5

    Runtime error '287' when trying to send email using Access 2010

    We are currently using Access 2007 and I've got a database that sends emails out to multiple users depending on the data that was entered. We are about to upgrade to Access 2010 and I am testing it now. I was originally getting runtime error '287' when I was adding addresses to a Recipient object. I got past that by adding the addresses in a string and concatenating. Now I'm getting the error with .Send. Does anyone know why? I'm not sure what to do to resolve this. Any help would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Post code and/or database for analysis. See instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bagwejm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    5
    Following is basically the code I'm using.
    Code:
    Sub SendEmail(TotalDur As String, Optional AttachmentPath)
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim rstRRec As DAO.Recordset
    Dim dbReporting As Database
    Dim stLinkCriteria As String
    Dim Ttest As String
    Dim j As Single
    Dim AttachmentArray(39) As Variant
    Dim strTo As String
    
       ' Create the Outlook session.
       Set objOutlook = CreateObject("Outlook.Application")
    
       ' Create the message.
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
       ' read from Email table to send email to correct people
       Set dbReporting = CurrentDb()
       Set rstRRec = dbReporting.OpenRecordset("tblEmailList", dbOpenDynaset)
       'test
       With objOutlookMsg
          Do While Not rstRRec.EOF
             If (1st Criteria is meet) Then
                strTo = strTo & (rstRRec.Fields(0)) & ";"
             Else
                If (2nd Criteria is meet) then 
                   strTo = strTo & (rstRRec.Fields(0)) & ";"
                Else
                   If (3rd Criteria is meet) Then
                      strTo = strTo & (rstRRec.Fields(0)) & ";"
                   End If
                End If
             End If
             rstRRec.MoveNext
          Loop
    
          strTo = Left(strTo, Len(strTo) - 1)
    
          '****************************************
    
          ' Set the Subject, Body, and Importance of the message.
          .To = strTo
          .Subject = "Subject Information”
          .Body = "Body Information”
          .Importance = olImportanceHigh 'High importance
          .Send
    
       End With
       Set objOutlookMsg = Nothing
       Set objOutlook = Nothing
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    The code syntax looks okay. I presume (1st Criteria is meet) and the other 2 criteria have expressions that can be evaluated in your actual code. Have you run Debug>Compile? If this is actual code procedure, why is the 'then' not capitalized? VBA should correct in valid code.

    I have never used the .Importance property. Might test without.

    Use code tags as I have modified your post and the indentation will be preserved. Code is more readable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    bagwejm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    5
    Thanks for looking at the code. I originally got the error when trying to use the .Recipient object but I change the code to use string concatenation. It fixed that problem but now on .Send I get the same error. I'll remove .Importance and see what happens. I'll let you know.

  6. #6
    bagwejm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    5
    No luck, still having the same problem. What causes that error? Would using CDO work in Access? Just grasping now.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    You did not address all comments/questions in my previous post.

    Don't know what is causing error. I use very similar code to send email.

    What is CDO?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    bagwejm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    5
    Sorry about that. Yes, it's compiled and in the code "then" is capitalized. I got sloppy when I started taking things out. Yes, each criteria has an expression that can be evaluated. The expressions are long and I tried to keep it simple. Using CDO is another way to send email but I think it is used when you don't have an email server.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Only thing I could do is evaluate your file if you want to provide. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. How can I send an email from access???
    By Asma in forum Programming
    Replies: 2
    Last Post: 12-07-2011, 07:49 AM
  2. VBA to Send email from Access
    By ped in forum Access
    Replies: 3
    Last Post: 08-11-2011, 05:37 PM
  3. Error 429 when try to send email
    By sjoaccess in forum Access
    Replies: 1
    Last Post: 02-04-2011, 07:45 PM
  4. Send email from Access DB Table
    By skaswani in forum Programming
    Replies: 3
    Last Post: 12-18-2010, 04:23 PM
  5. Send email from Access thru Outlook
    By ZMAN in forum Forms
    Replies: 2
    Last Post: 11-27-2010, 06:10 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