My environment is:
- Access 2007
- .accdb file
- Am in datasheet view when stepping through
- Early binding
- Libraries:
VB for Apps
MS Access 12.0 Obj. Lib.
MS OFC 12.0 Access db engine Obj. Lib.
MS VB for Apps Extensibility 5.3
MS VBScript Regular Expressions 5.5
MS Outlook 12.0 Obj. Lib.
MS ActiveX Data Objects 2.8 Lib.
OLE Automation
The code is hanging up on the "Exit Sub" line, #14.
When Outlook is closed: Hangs up on the "Exit Sub" when it should be going to SECT1_ERR.
When Outlook is open: Does the same thing, just runs faster.
When I take out the "Exit Sub", the error IS caught and the MsgBox pops, but then I get stuck in the loop of Resume Next-->GetObject-->MsgBox.
If Outlook is already opened or opened by the user after a first message instance, I don't see why my code won't continue from the "GetObject" statement to "Exit Sub" and on to the next section (SECT2) of my code....? No versions I'm trying work.
Here it is, along with the section that comes after it:
Expand|Select|Wrap|Line Numbers
- Option Explicit
- Option Compare Database
- Public Sub A1S1_Form_Re_send_Welcome_E_Mail_Only_Button_Click()
- On Error GoTo SECT1_ERR:
- Dim OlApp As Object
- Set OlApp = GetObject("", "Outlook.Application")
- ' Debug.Print "See If Outlook Is Closed", Err.Number, Err.Description
- Exit Sub
- SECT1_ERR:
- MsgBox "MS Outlook not open." & vbCrLf & "Please open Outlook, then hit automation button again." & vbCrLf & "Error #: " & Err.Number & " - " &
- Err.Description, vbExclamation + vbOKOnly, "Open Outlook"
- Resume Next
- ' Template is now retrieved to base e-mail on...
- On Error GoTo SECT2_ERR
- Dim objOutlookMsg As Outlook.MailItem
- Set objOutlookMsg = OlApp.CreateItemFromTemplate("J:\Database Work\A1 Tracking DB & Related\A1 Form Button Automation Email Templates\Employee A1 Welcome Outlook Template.oft")
- ' Debug.Print "Open template object", Err.Number, Err.Description
- SECT2_EXIT:
- Exit Sub
- SECT2_ERR:
- MsgBox "Error opening Outlook template object." & vbCrLf & "Error #: " & Err.Number & " - " & Err.Description, vbExclamation + vbOKOnly, "Open Outlook Template"
- Resume SECT2_EXIT
Note: I previously tried the CreateObject method to create an instance of Outlook if it was closed, but to no avail (got error 438-object doesn't support this property/method).
Thank you for looking at this problem. It is appreciated. Any advice will further be!
Frank