A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

If loop not running



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 10th 09, 07:49 PM posted to microsoft.public.outlook.program_vba
mitch
external usenet poster
 
Posts: 47
Default If loop not running

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 (" LoopValueBefo " & 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
Ads
  #2  
Old August 10th 09, 08:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default If loop not running

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Mitch" wrote in message
...
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 (" LoopValueBefo " & 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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Attachment (once again) Dan Outlook and VBA 6 December 28th 09 03:49 PM
Loop Attachment Dan Outlook and VBA 0 May 27th 09 03:18 AM
Loop through future appointments Daniel Outlook and VBA 2 July 5th 07 01:30 PM
CDO Loop problem - Fix could be useful for many people. Sue Mosher [MVP-Outlook] Outlook and VBA 0 March 30th 07 05:08 PM
Reverse loop? yonina Outlook and VBA 2 February 2nd 06 09:10 AM


All times are GMT +1. The time now is 06:45 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.