When you preview a report, right-click offers the option, Send to... -> Mail Recipient.
I need to catch this event and execute code the reads the recipient e-mail address as typed into Outlook when it appears. This code should be in a module in the Access database.
If possible, I would also like to read the Subject.
It's hard to find answers on the Web, and despite some experience with Access and VBA, I don't know how to even start.
Edit: From Dmitry's answer I found this loop through Inspectors,
Private Sub Form_Timer()
Dim myInspectors As Outlook.Inspectors
Dim x As Integer
Dim iCount As Integer
Set myInspectors = Application.Inspectors
iCount = Application.Inspectors.Count
If iCount > 0 Then
For x = 1 To iCount
MsgBox myInspectors.Item(x).Caption
Next x
Else
MsgBox "No inspector windows are open."
End If
End Sub
but it gives this compile error:
Edit 2:
I have moved the code into a function, and when Outlook is running, I get no errors from this GetObject call. But with this function on a 2s timer, objApp.Inspectors.Count remains 0 while I compose an email and send it.
Public Function checkInspectors() As Boolean
Dim myInspectors As Outlook.Inspectors
Dim OutLookWasNotRunning As Boolean
Dim objApp As Object
Set objApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then OutLookWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
If Not OutLookWasNotRunning Then
Set myInspectors = objApp.Inspectors
Dim x As Integer
Dim iCount As Integer
iCount = objApp.Inspectors.Count
If iCount > 0 Then
For x = 1 To iCount
Debug.Print myInspectors.Item(x).Caption
Next x
Debug.Print "---"
Else
'MsgBox "No inspector windows are open."
End If
End If
End Function