473,440 Members | 1,863 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,440 software developers and data experts.

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 8352
"Mark" <ma*********@ntlworld.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.greenlnk.net...
"Mark" <ma*********@ntlworld.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
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...
1
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...
143
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...
16
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...
9
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
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...
6
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...
1
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...
2
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...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.