If loop not running

Status
Not open for further replies.
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.

"Mitch" <Mitch> wrote in message

news:7B6C12A0-FB06-4CD1-97B4-0DB279AFA1B0@microsoft.com...
> 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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S Macro for Loop through outlook unread emails Outlook VBA and Custom Forms 2
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
A ItemAdd on Imap Folder get endless loop after saving item Using Outlook 5
makinmyway Trouble Installing BCM Outlook 2013; Endless Install Loop Happens Using Outlook 0
W Broken Folder Loop - Outlook 2007 (.oft files) Using Outlook 2
Forum Admin Endless loop when to the new Outlook Connector Using Outlook.com accounts in Outlook 0
S Business Contact Manager (BCM) causing Outlook crash loop BCM (Business Contact Manager) 3
K loop through distribution group (and potentially, embedded DGs) by Outlook VBA and Custom Forms 1
H For Each loop not getting all Email Items Outlook VBA and Custom Forms 3
S Loop mail items within a Custom Search Folder Outlook VBA and Custom Forms 1
M Outlook VBA Form not finding FOR LOOP -- Error message Outlook VBA and Custom Forms 2
R Loop Attachment (once again) Outlook VBA and Custom Forms 6
F Running Scripts in Outlook 2021 Using Outlook 0
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
A VBscript stops running after updating form Outlook VBA and Custom Forms 1
N contact notepad 'style' getting changed after clicking and running Activities Using Outlook 2
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
S Problem running Command button code Outlook VBA and Custom Forms 2
B Automation error running VB macro code Outlook VBA and Custom Forms 8
Diane Poremsky OUTLOOK.EXE continues running after you exit Outlook Using Outlook 0
Diane Poremsky Running Outlook Macros on a Schedule Using Outlook 0
B ActiveExplorer return NULL on new Window user login and running Outlook first time Using Outlook 1
JorgeDario Template oft that contains VBScript Is not running Using Outlook 1
M Mark Complete keyboard shortcut... on a mac running Windows Bootcamp Using Outlook 0
N Outlook 2007 To-Do-List status keeps running Using Outlook 2
S The attempted operation failed ... 2nd time running code Outlook VBA and Custom Forms 3
G email returns after running macro to move emails Outlook VBA and Custom Forms 1
P Outlook Macro keeps running for the same messagage Using Outlook 2
N Running multiple macros upon sending Outlook VBA and Custom Forms 6
M Accessing BCM with Excel / Running Reports BCM (Business Contact Manager) 1
G Error when running scanpst.exe Using Outlook 1
V Running scripts with Outlook 2013 Using Outlook 17
D Stopping "do you want to continue running scripts on this page" warnings Using Outlook 4
M Running macros in tasks sent out as meeting requests in invitees machine Using Outlook 4
N Rules stop running automatically Using Outlook 10
D VBA code running on Server? Shared mailbox email routing Using Outlook 3
T WAB editing: To help prevent malicious code from running.......... Using Outlook 18
M Outlook.exe 1.2Gb memory usage if running certain BCM reports BCM (Business Contact Manager) 8
M Why rules stop running automatically? Using Outlook 1
V Trouble Running Outlook 2007 and 2010 Using Outlook 4
S CSCANPST To Automate Running SCANPST.EXE Using Outlook 1
L remove a hotmail account from Outlook 2007 running on Vista home premium Using Outlook.com accounts in Outlook 1
S Outlook 2007 Running on Windows 7 hangs on send Using Outlook 7
A running code after the new inspector is visible Outlook VBA and Custom Forms 1
M Running Outlook as Scheduled task Outlook VBA and Custom Forms 1
S ActiveExplorer return NULL on new Window user login and running Outlook first time Outlook VBA and Custom Forms 19
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
A Running Code in Side by side calendar view Outlook VBA and Custom Forms 2
G Re:Running a Macro when email arrives Outlook VBA and Custom Forms 1
D Running a Program from Custom Action Rule Outlook VBA and Custom Forms 1

Similar threads

Back
Top