Asked by:
Office 365 Access error 287 with Outlook

Question
-
My company just upgraded us from Office/Access/Outlook 2007 to Office/Access/Outlook 365. I have an Access Database with come Visual Basic that runs a query and then opens an Outlook message and populates the To/Recipients. The VB works fine under Access 2007, but now with Access 365, I get an Error 287: Application-defined or object-defined error. I have a feeling that it's security related, since our Windows 10/Office 365 PCs are now very locked-down (no Admin rights, etc.), plus, I tried the same VB code on my Windows 10/Office 365 PC at home (with normal security restrictions) and it worked as expected. Is there a place that I should be looking on my locked-down Windows 10/Office 365 PC for a security setting to allow the VB to work?
Here's the VB:
Option Compare Database
Option Explicit
Private Sub cmdCancelEmail_Click()
DoCmd.Close acForm, "frmEmailSelector"
End Sub
Private Sub cmdOKEmail_Click()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim strSQL As String
Dim MyString As String
Dim myResponse As Integer
Dim fso As FileSystemObject
Set fso = New FileSystemObject
' Now, we open Outlook for our own device...
Set MyOutlook = New Outlook.Application
' Set up the database
Set db = CurrentDb
' Query
strSQL = ""
strSQL = strSQL & "SELECT [tblRecipients].Email "
strSQL = strSQL & "FROM [tblRecipients] INNER JOIN [tblProduction] "
strSQL = strSQL & "ON [tblRecipients].[Recipient ID] = [tblProduction].[Recipient ID] "
strSQL = strSQL & "WHERE ((([tblProduction].Docket)= Eval('[Forms]![frmDocketSelector]![cboDocket]')) "
strSQL = strSQL & "AND (([tblProduction].[E-Mail List Type])= Eval('[Forms]![frmEmailSelector]![cboIntExt]')) "
strSQL = strSQL & "OR (([tblProduction].Docket)= Eval('[Forms]![frmDocketSelector]![cboDocket]')) "
strSQL = strSQL & "AND (([tblProduction].[E-Mail List Type])='Both')) "
strSQL = strSQL & "ORDER BY [tblProduction].[Recipient ID]"
Set MailList = db.OpenRecordset(strSQL)
If MailList.EOF Then
MsgBox "There are no " & [Forms]![frmEmailSelector]![cboIntExt] & " email recipients in this docket."
Else
' now, this is the meat and potatoes.
' this is where we loop through our list of addresses,
' adding them to e-mails and sending them.
Do Until MailList.EOF
' This creates the e-mail
' We need to move it BEFORE we start the loop, since
' we don't want to make a bunch of e-mails, we just want one.
Set MyMail = MyOutlook.CreateItem(olMailItem)
' this is where we loop through our list of addresses,
' and we add them to the RECIPIENTS collection
Do Until MailList.EOF
' This adds the address to the list of recipients
MyMail.Recipients.Add MailList("EMail")
'And on to the next one...
MailList.MoveNext
Loop
MyMail.Display
Loop
'Cleanup after ourselves
Set MyMail = Nothing
'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.
' MyOutlook.Quit
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End If
DoCmd.Close acForm, "frmEmailSelector"
ErrHandler:
If Err.Number = 94 Or Err.Number = -2147352567 Then
MsgBox "Missing an email address.", vbOKOnly
DoCmd.Close acForm, "frmEmailSelector"
Else
If Err.Number = 0 Then
DoCmd.Close acForm, "frmEmailSelector"
Else
MsgBox Err.Number & ": " & Err.Description, _
vbOKOnly, "Error"
DoCmd.Close acForm, "frmEmailSelector"
End If
End If
End Sub
Private Sub Form_Current()
DoCmd.MoveSize 9640, 4280
End Sub
Tuesday, May 7, 2019 2:31 AM
All replies
-
Are there any references listed as Missing (code window > Tools > References)?
Does the code compile (code window > Debug > Compile)?
Set a breakpoint at the top of the function and carefully step through, inspecting variables etc. Identify the line of code that causes the problem.
If you are new to debugging, maybe my video tutorials would help: https://www.youtube.com/results?search_query=stiphout+mvp+hour+debugging-Tom. Microsoft Access MVP
Tuesday, May 7, 2019 3:13 AM -
There are no missing References.
The code compiles without error.
When I set a Breakpoint, it works until this line: DoCmd.Close acForm, "frmEmailSelector"
Thanks for your help!
Tuesday, May 7, 2019 2:21 PM -
Inspect the code for that form. Perhaps there are additional breakpoints that should be set in its Form_Unload or Form_Close event, if any.
If that form has subforms, those could have code as well that fires when the parent is closing.
-Tom. Microsoft Access MVP
Wednesday, May 8, 2019 3:16 AM -
I believe that I've done all of that, and I'm no closer to a resolution.
I still believe that it's a security issue. Since:
1) it runs fine under Windows 7 with Outlook 2010 and Access 2010.
2) it runs fine under an 'unlocked' Windows 10 with Outlook 365 and Access 365 (version 16).
3) it fails under my work 'locked down' Windows 10 with Outlook 365 and Access 365 (version 16).
Are you aware of any security parameters that I can look at that could be causing the error 287 on my work PC?
Thanks again for any help you can give.
Wednesday, May 8, 2019 12:46 PM -
I believe you have not nailed down why the error occurs on that line. DoCmd.Close does not generate that error. More debugging and creative investigations seem needed to pinpoint the problem.
A thorough search of MSFT KB articles might help as well.
If it THEN points to security, so be it.
I don't work in locked down environments. Maybe others who do can chime in and offer suggestions.
-Tom. Microsoft Access MVP
Wednesday, May 8, 2019 1:29 PM