473,473 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error Handling Loop...Stuck Inside!

34 New Member
I'm not sure why this code is hanging up. When my user clicks a form button, I'm simply trying to check to see if Outlook is open, and if it isn't, display a message box reminding them to open Outlook. If it is already open, I (obviously) want the code to skip the error code and continue.

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
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. Public Sub A1S1_Form_Re_send_Welcome_E_Mail_Only_Button_Click()
  5.  
  6. On Error GoTo SECT1_ERR:
  7.  
  8. Dim OlApp As Object
  9.  
  10. Set OlApp = GetObject("", "Outlook.Application")
  11.  
  12. ' Debug.Print "See If Outlook Is Closed", Err.Number, Err.Description
  13.  
  14. Exit Sub
  15.  
  16. SECT1_ERR:
  17. MsgBox "MS Outlook not open." & vbCrLf & "Please open Outlook, then hit automation button again." & vbCrLf & "Error #: " & Err.Number & " - " & 
  18. Err.Description, vbExclamation + vbOKOnly, "Open Outlook"
  19.  
  20. Resume Next
  21.  
  22. ' Template is now retrieved to base e-mail on...
  23.  
  24. On Error GoTo SECT2_ERR
  25.  
  26. Dim objOutlookMsg As Outlook.MailItem
  27.  
  28. Set objOutlookMsg = OlApp.CreateItemFromTemplate("J:\Database Work\A1 Tracking DB & Related\A1 Form Button Automation Email Templates\Employee A1 Welcome Outlook Template.oft")
  29.  
  30. ' Debug.Print "Open template object", Err.Number, Err.Description
  31.  
  32. SECT2_EXIT:
  33. Exit Sub
  34.  
  35. SECT2_ERR:
  36. MsgBox "Error opening Outlook template object." & vbCrLf & "Error #: " & Err.Number & " - " & Err.Description, vbExclamation + vbOKOnly, "Open Outlook Template"
  37.  
  38. Resume SECT2_EXIT
Note: When I add a "SECT1_EXIT" before the error handling and a "Resume SECT1_EXIT" after it, code hangs up in the same place - on "SECT1_EXIT", when Outlook is open or not.
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
Feb 17 '12 #1
2 2138
Guido Geurs
767 Recognized Expert Contributor
SECT1_ERR:
MsgBox "MS Outlook not open." & vbCrLf ...

MsgBox ... ends on: "&"

Must be:

... & Err.Number & " - " & _
Feb 18 '12 #2
soule
34 New Member
Hi, Guido Geurs,

Thank you for replying! My actual statement doesn't currently wrap in the VBE and I'll be sure to use an underscore when I clean it up. Thanks for the concern.

Frank
Feb 21 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
8
by: Niraj Khandwala | last post by:
Dear all, this error handling has been a pain since so manya days using ASP 3.0 with IIS 5.0 on W2K server Created a custom error page using the Server.GetLastError() and works fine in most of...
3
by: Alberto Giménez | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there! I'm doing some homework (almost finished), but now i'm reconsidering a design decission I made at the beginning. This is about error...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
2
by: Omar Abid | last post by:
Reason of this project: Error handling is one of the most difficult thing that may afford a programmer. It isn't as easy as you think and handling errors in a program some time can make errors...
4
by: raylopez99 | last post by:
See comment below. This is a simple problem but I'm a little rusty. How to break out of a event loop (here _Paint)? I've tried if/else, case, etc but not quite what I want--I keep getting the JIT...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.