473,425 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Error Handling Loop...Stuck Inside!

34
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 2137
Guido Geurs
767 Expert 512MB
SECT1_ERR:
MsgBox "MS Outlook not open." & vbCrLf ...

MsgBox ... ends on: "&"

Must be:

... & Err.Number & " - " & _
Feb 18 '12 #2
soule
34
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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...

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.