By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,624 Members | 1,747 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,624 IT Pros & Developers. It's quick & easy.

Exit code when certain criteria is met

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.