469,917 Members | 1,874 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

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 8166
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
143 posts views Thread by suri | last post: by
6 posts views Thread by Scott McDaniel | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.