If loop not running

  • Thread starter Thread starter Mitch
  • Start date Start date
M

Mitch

Using Outlook 2003, this script runs whne a users clicks a button to submit
emails with attachments with a different frequency.

It basically gets FreqAtt.Value from another text box, LoopCount is used to
count until it reaches FreqAtt.Value. CB1...CB20 are email addresses. They
all check out fine.

I used dialogue boxes before, during and after the IF statement and it
displayes the right values. 1 2, 2 2. But if I used those values, the IF
statement still isn't hit. (The IF statement that adds an attachment to the
email). Without the IF statement the attachments work.

Is there some kind of specific reason an IF wouldn't work here?

Dim LoopCount

LoopCount = 1

For I = 1 To NumberEmails.Value

Set objMail = Application.CreateItem(0)

If CB1.Value = True Then
Set rcpt = objMail.Recipients.Add(CB1.Tag)
End If
If CB2.Value = True Then
Set rcpt = objMail.Recipients.Add(CB2.Tag)
End If
' ... (Code removed, it's all th same IF's all have corresponding End IF.)
If CB19.Value = True Then
Set rcpt = objMail.Recipients.Add(CB19.Tag)
End If
If CB20.Value = True Then
Set rcpt = objMail.Recipients.Add(CB20.Tag)
End If
If CB1 + CB2 + CB3 + CB4 + CB5 + CB6 + CB7 + CB8 + CB9 + CB10 + CB11 +
CB12 + CB13 + CB14 + CB15 + CB16 + CB17 + CB18 + CB19 + CB20 = False Then
MsgBox ("No Emails Selected"), vbOKOnly
End If

objMail.Subject = SubjectLine + " " + CStr(I)
objMail.Body = "Records Management Test Message " + CStr(I)

MsgBox (" LoopValueBefore: " & LoopCount & " " & FreqAtt.Value), vbOKOnly
If FreqAtt.Value = LoopCount Then
Set myAtt = objMail.Attachments
myAtt.Add AttachmentPath.Value
MsgBox (" LoopValue In IF: " & LoopCount & " " & FreqAtt.Value),
vbOKOnly
LoopCount = 0
End If
MsgBox (" LoopValueAfter: " & LoopCount & " " & FreqAtt.Value), vbOKOnly

LoopCount = LoopCount + 1

objMail.Save
objMail.Send
Next I
 
It appears to me that you're trying to compare LoopCount, a numeric value,
with the string value of a textbox control. You need to convert one or the
other to a compatible format. Either convert LoopCount to a string value or
the textbox value to a numeric value.
 
Back
Top