How to stop the procedure instead of continuing sending a mail afternone of criteria match

G

Gerry

Hello

Descprition of situation:

As you can see here we have a loop (While not ... Wend) which contains
2 'case conditions'.
What is my problem. At the end of this piece of code there is more
code that prepares a mail containing all constatations.
My problem:
In case none of the 'case criteria' match I want to end the procedure
preliminary so the mail doesn't have to be sent.
Can anybody tell me how I have to proceed? Thanks a lot!

<check of files in a Recordset>

nomb = Rs1.RecordCount
Rs1.MoveFirst
While Not (Rs1.EOF)

resultstr = ""
Posnr = Rs1.Fields("Position")
Instrnr = Rs1.Fields("INSTRUMENT")
Select Case Abs(Rs1.Fields("Position"))

Case 5 To 10
resultstr = Instrnr & ":" & Posnr & "EUR"
MsgBox ("Nobody ")

Case 11 To 20
resultstr = resultstr & Instrnr & ":" & Posnr & "EUR"
MsgBox ("Go for It")

End Select
Rs1.MoveNext
Wend
MsgBox ("All Positions checked!")

..... ?? ..... If the criteria don't match, the mail that is generated
hereafter doesn't have to be sent.

<code which creates a general mail containing constatations even if
there is nothing relevant to mention>
 
S

Stuart McCall

Gerry said:
Hello

Descprition of situation:

As you can see here we have a loop (While not ... Wend) which contains
2 'case conditions'.
What is my problem. At the end of this piece of code there is more
code that prepares a mail containing all constatations.
My problem:
In case none of the 'case criteria' match I want to end the procedure
preliminary so the mail doesn't have to be sent.
Can anybody tell me how I have to proceed? Thanks a lot!

<check of files in a Recordset>

nomb = Rs1.RecordCount
Rs1.MoveFirst
While Not (Rs1.EOF)

resultstr = ""
Posnr = Rs1.Fields("Position")
Instrnr = Rs1.Fields("INSTRUMENT")
Select Case Abs(Rs1.Fields("Position"))

Case 5 To 10
resultstr = Instrnr & ":" & Posnr & "EUR"
MsgBox ("Nobody ")

Case 11 To 20
resultstr = resultstr & Instrnr & ":" & Posnr & "EUR"
MsgBox ("Go for It")

End Select
Rs1.MoveNext
Wend
MsgBox ("All Positions checked!")

.... ?? ..... If the criteria don't match, the mail that is generated
hereafter doesn't have to be sent.

<code which creates a general mail containing constatations even if
there is nothing relevant to mention>

Insert the line:

If resultStr <> "" Then Exit Sub

after your MsgBox line.
 
G

Guest

You can add an additional Case Statement as follows

Case Else
rs1.movelast

Then the rs1.EOF will validate the While loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top