473,789 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exit code when certain criteria is met

Hi All,
I'm trying my hardest to learn VBA but have run into a problem which
hopefully someone can guide me with.

Basically what I am trying to achieve is to get the database to check the
users Outlook Inbox every hour for the existence of a mail from a certain
address. If it finds one, it saves the attachment and then imports the
contents of the attachment. However, before the import takes place, the text
file is checked to make sure that certain criteria are met.

At a timer event, a Private Sub runs which during it's course ,calls 2 other
public subs. One of the public subs does a couple of checks to make sure
that the data is correct. If it finds that it is not, I want all the code to
stop. I tried this by using Exit Sub. This quits the Public sub but allows
the Private sub to continue. I need to stop the Private sub from running :o(

Can anyone offer any suggestions on how best to achieve this?

Many thanks,

Mark
Nov 25 '05 #1
4 8366
"Mark" <ma*********@nt lworld.com> wrote in message
news:ee******** *******@newsfe7-gui.ntli.net...
Hi All,
I'm trying my hardest to learn VBA but have run into a problem which
hopefully someone can guide me with.

Basically what I am trying to achieve is to get the database to check the
users Outlook Inbox every hour for the existence of a mail from a certain
address. If it finds one, it saves the attachment and then imports the
contents of the attachment. However, before the import takes place, the
text file is checked to make sure that certain criteria are met.

At a timer event, a Private Sub runs which during it's course ,calls 2
other public subs. One of the public subs does a couple of checks to make
sure that the data is correct. If it finds that it is not, I want all the
code to stop. I tried this by using Exit Sub. This quits the Public sub
but allows the Private sub to continue. I need to stop the Private sub
from running :o(

Can anyone offer any suggestions on how best to achieve this?


One approach would be to have the "public" sub return a boolean value and
have an If ... Then clause in the "private" one to evaluate it along the
lines of:

Private Sub MyCode()

If SubPublic Then ' The public sub has returned "True"
Exit Sub
Else
Do other stuff
End If

End Sub

Pretty high level I know but I hope it helps.

Regards,
Keith.
www.keithwilby.com
Nov 25 '05 #2
Hi Keith,
It took a bit of research to figure out how to return a Boolean but once
I'd cracked that, the If clause worked perfectly. Many thanks for pointing
me in the right direction.

Regards,

Mark

"Keith W" <he**@there.com > wrote in message
news:43******** **@glkas0286.gr eenlnk.net...
"Mark" <ma*********@nt lworld.com> wrote in message
news:ee******** *******@newsfe7-gui.ntli.net...
Hi All,
I'm trying my hardest to learn VBA but have run into a problem which
hopefully someone can guide me with.

Basically what I am trying to achieve is to get the database to check the
users Outlook Inbox every hour for the existence of a mail from a certain
address. If it finds one, it saves the attachment and then imports the
contents of the attachment. However, before the import takes place, the
text file is checked to make sure that certain criteria are met.

At a timer event, a Private Sub runs which during it's course ,calls 2
other public subs. One of the public subs does a couple of checks to make
sure that the data is correct. If it finds that it is not, I want all the
code to stop. I tried this by using Exit Sub. This quits the Public sub
but allows the Private sub to continue. I need to stop the Private sub
from running :o(

Can anyone offer any suggestions on how best to achieve this?


One approach would be to have the "public" sub return a boolean value and
have an If ... Then clause in the "private" one to evaluate it along the
lines of:

Private Sub MyCode()

If SubPublic Then ' The public sub has returned "True"
Exit Sub
Else
Do other stuff
End If

End Sub

Pretty high level I know but I hope it helps.

Regards,
Keith.
www.keithwilby.com

Nov 25 '05 #3
Keith W wrote:
Private Sub MyCode()

If SubPublic Then ' The public sub has returned "True"
Exit Sub
Else
Do other stuff
End If

End Sub


I say, does a sub return a boolean of some sort? My approach would have
been the same except to have made the "SubPublic" a public function
returning some value (in this case a boolean).
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 25 '05 #4
Tim Marshall wrote:
Keith W wrote:
Private Sub MyCode()

If SubPublic Then ' The public sub has returned "True"
Exit Sub
Else
Do other stuff
End If

End Sub

I say, does a sub return a boolean of some sort? My approach would have
been the same except to have made the "SubPublic" a public function
returning some value (in this case a boolean).


I think the OP knew what I meant ;-)
Nov 26 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1889
by: Maxwell Hammer | last post by:
An application I am developing executes many threads and then has a "monitor" part that waits for certain events. One of these events causes the application to have to shutdown. On shutdown the monitor part notifies the threads of a shutdown, and the threads must cleanup and exit. When all threads have exited the monitor itself exits. The traceback below occured on a shutdown. At the time there was only one thread running, however the...
1
8527
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error condition and if it finds it it notifies the user with a MessageBox and then on the next line of code (example in a minute) it calls Application.Exit(). To my astonishment, I stepped through the code with the debugger, and watched it call...
143
8110
by: suri | last post by:
Hello I downloaded glibc and tried looking for the code that implements the sine function i couldnt find the file. i went to the math directory and found math.h.. i guess that needs to be included for the sine function. but which .c file implements the sine/cosine and other trig fns thanks
16
6736
by: LP | last post by:
Hi, Considering code below. Will it make GC to actually collect. One application creates new instances of a class from 3rd party assembly in a loop (it has to). That class doesn't have .Dispose or any similar method. I want to make sure GC keeps up with the loop. My reasoning if Thread.Sleep(1000) is called; GC will take priority it do its work, right? GC.Collect(); GC.WaitForPendingFinalizers(); System.Threading.Thread.Sleep(1000);
9
3447
by: Sandy | last post by:
Hello - I need either a cheap tool or code & DB that calculates, eg. within 50-mile radius of a zip code. Anyone have any suggestions? -- Sandy
6
3345
by: Scott McDaniel | last post by:
I'm using Visual Studio 2005 with the .NET 2.0.50727 framework, and we're using the standard Datagrid control bound to a SQL Server. We have two groups of users - "full edit" users, and "view only" users. We would like to disable the EditCommandColumn of our Datagrid (named dgCertificates) for viewonly users. The intent is that viewonly would, obviously, only be able to view data and not maniupulate it in any way. I've tried the...
6
7731
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If IsNull(Me!NotExpectingGreenTickets) Then DoCmd.CancelEvent Exit Sub End If End Sub
1
1898
by: Bhujanga | last post by:
I have some reports whose purpose is to show whether any records currently meet certain criteria, so of course the report is based on a query where that criteria is defined. If there don't happen to be any records that satisfy the criteria at a particular time then the report produces with one line in the detail section that says "#Error". This confuses the users becuase they think there is something wrong with the report. Is there a way to...
2
2102
by: rleepac | last post by:
I have a form with a tabbed control on it. I am trying to set certain criteria for some of the tabs to show only when info from other fields meet criteria. Specifically, I have two fields. Both are combo boxes (using tables as the row source). What I want is that when empType combo box is set to Prehire (8 in the table) AND the empPosition combo box is set to Police Officer then the Police_MSK tab is visible. But if both of those...
0
9665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.