Results 1 to 8 of 8
  1. #1
    Nuke1096 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2013
    Posts
    53

    runtime error 287 at the .send line when sending Outlook Email

    I cant seem to figure out why I keep getting "Runtime 287 Application-defined or object-defined error" when my code tries to send an outlook email. Here is my code currently for the form.






    My Button Code

    Code:
    Private Sub SubmitButton_Click()
     
    Call send_Breakdown
      
    MsgBox "GPS Unit Diagnostics Information Successfully Entered Into The Database"
    DoCmd.Close acForm, "Form_New_GPS_Diags"
        
    End Sub
    
    
    



    Outlook Code


    Code:
    
    
    Code:
    Sub send_Breakdown()
    
    
    Dim objOutLook As Object
    Dim MailOutLook As Object
    
    
    ' Create the Outlook Session
    Set objOutLook = CreateObject("Outlook.Application")
    ' Create the Message
    Set MailOutLook = objOutLook.CreateItem(olMailItem)
    
    
    
    
    mailroster = "abc@yahoo.com"
      
    
    
    With MailOutLook
    
    
     .To = mailroster
     .Subject = "GPS Diagnostics Report!"
     .body = "A GPS Diagnostics Test has been run on a possibly defective unit! The details of the test are listed below..."
     .send
     
    End With
       
    Set objOutLook = Nothing
    Set MailOutLook = Nothing
    
    
    
    
    End Sub



    Any help is much appreciated. I've been pulling my hair out over this cause it was working fine on Friday and nothing changed.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What references are you using when you are running this code?

    Is microsoft outlook one of them?

    To view the references from the VB window click on TOOLS > REFERENCES, if you're going to use outlook objects look for a reference name that is something close to "Microsoft Outlook XX.X Object Library"

    Make sure it's checked off and you should be able to run the code.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    That code wouldn't require the Outlook reference as it uses late binding. With late binding you typically can't use constants like olMailItem though, so I'm a little surprised it ever worked.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Nuke1096 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2013
    Posts
    53
    Somehow it's working again with nothing changed. I have no idea whats going on to be honest.

    pbaldy, how would you write the code differently without the olmailitem? Like I said, its working again now, but I have no confidence it'll stay that way.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    That's a constant, which generally have numeric equivalents. My code looks like:

    Set objMail = objOutlook.CreateItem(0)

    so 0 is the numerical equivalent of olMailItem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Nuke1096 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2013
    Posts
    53
    Thank you! I switched it to 0 and its still working fine.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    No problem. Like I said, I'm a little surprised it worked as you had it. Getting errors on constants like that is what often trips people up when they switch from early binding to late binding. You don't by chance have the reference rpeare mentioned in post 2 checked do you? That might explain it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Nuke1096 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2013
    Posts
    53
    It was unchecked initially, but I tried checking it and unchecking a few times to see if it made any difference and it didnt seem to. Right now its unchecked.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-05-2013, 12:13 PM
  2. Replies: 8
    Last Post: 05-29-2012, 02:10 PM
  3. sending data into an email body - outlook
    By webisti in forum Access
    Replies: 6
    Last Post: 02-15-2012, 07:05 AM
  4. Replies: 1
    Last Post: 03-09-2006, 01:50 PM
  5. Sending email via Outlook (and Exchange2003) from Access2003
    By Larry Elfenbein in forum Programming
    Replies: 0
    Last Post: 11-15-2005, 09:03 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