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

Outlook VBA Form not finding FOR LOOP -- Error message



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 7th 09, 10:25 PM posted to microsoft.public.outlook.program_vba
mitch
external usenet poster
 
Posts: 47
Default Outlook VBA Form not finding FOR LOOP -- Error message

I'm using Outlook 2003 SP3, using a VBA Form created throug Outlook, it
basically checks some checkboxes for a value of True, then adds an email
address. It works perfectly fine when I do it as a macro.

When I plug it into the form, my FOR Loop "NEXT" isn't finding the loop. I
get a Next neesda for loop even though I have one in it.

Here's my code on Mouse click submit. [Note: NumberEmails.Value is a number
taken from a text box whos value is modifed by SpinButton]

Mind you I have replaced some string variables I hardcoding into the macro
as variables, so those have not been tested just yet, but I'd expect them to
work.

Private Sub SubmitButton_Click()

Set OutlookApp = CreateObject("Outlook.Application")
Dim objMail As Outlook.MailItem
Set objMail = OutlookApp.CreateItem(0)

Dim rcpt As Recipient

For i = 1 To NumberEmails.Value
Set objMail = Application.CreateItem(0)
If CB1.Value = True Then
Set rcpt = objMail.Recipients.Add(CB1.Tag)
If CB2.Value = True Then
Set rcpt = objMail.Recipients.Add(CB2.Tag)
If CB3.Value = True Then
Set rcpt = objMail.Recipients.Add(CB3.Tag)
If CB4.Value = True Then
Set rcpt = objMail.Recipients.Add(CB4.Tag)
If CB5.Value = True Then
Set rcpt = objMail.Recipients.Add(CB5.Tag)
If CB6.Value = True Then
Set rcpt = objMail.Recipients.Add(CB6.Tag)
If CB7.Value = True Then
Set rcpt = objMail.Recipients.Add(CB7.Tag)
If CB8.Value = True Then
Set rcpt = objMail.Recipients.Add(CB8.Tag)
If CB9.Value = True Then
Set rcpt = objMail.Recipients.Add(CB9.Tag)
If CB10.Value = True Then
Set rcpt = objMail.Recipients.Add(CB10.Tag)
If CB11.Value = True Then
Set rcpt = objMail.Recipients.Add(CB11.Tag)
If CB12.Value = True Then
Set rcpt = objMail.Recipients.Add(CB12.Tag)
If CB13.Value = True Then
Set rcpt = objMail.Recipients.Add(CB13.Tag)
If CB14.Value = True Then
Set rcpt = objMail.Recipients.Add(CB14.Tag)
If CB15.Value = True Then
Set rcpt = objMail.Recipients.Add(CB15.Tag)
If CB16.Value = True Then
Set rcpt = objMail.Recipients.Add(CB16.Tag)
If CB17.Value = True Then
Set rcpt = objMail.Recipients.Add(CB17.Tag)
If CB18.Value = True Then
Set rcpt = objMail.Recipients.Add(CB18.Tag)
If CB19.Value = True Then
Set rcpt = objMail.Recipients.Add(CB19.Tag)
If CB20.Value = True Then
Set rcpt = objMail.Recipients.Add(CB20.Tag)
Else: MsgBox ("No Emails Selected"), vbOKOnly

objMail.Subject = SubjectLine + CStr(i)
objMail.Body = "Test Message " + CStr(i)

Set myAtt = objMail.Attachments
myAtt.Add = AttachmentPath

objMail.Save
objMail.Send
Next

Set objMail = Nothing
Set myAtt = Nothing
Set rcpt = Nothing

End Sub
------
Private Sub SpinButton1_SpinDown()
If NumberEmails.Value = 1 Then NumberEmails.Value = 1 Else
NumberEmails.Value = NumberEmails.Value - 1
End Sub
------
Private Sub SpinButton1_SpinUp()
If NumberEmails.Value = 20 Then NumberEmails.Value = 20 Else
NumberEmails.Value = NumberEmails.Value + 1
End Sub
----------
Ads
  #2  
Old August 7th 09, 10:41 PM posted to microsoft.public.outlook.program_vba
mitch
external usenet poster
 
Posts: 47
Default Outlook VBA Form not finding FOR LOOP -- Error message

Found that my If statements were messing it up, wonder if there's a better
way to do this. A for loop to run through my 20 if statements ?

"Mitch" wrote:

I'm using Outlook 2003 SP3, using a VBA Form created throug Outlook, it
basically checks some checkboxes for a value of True, then adds an email
address. It works perfectly fine when I do it as a macro.

When I plug it into the form, my FOR Loop "NEXT" isn't finding the loop. I
get a Next neesda for loop even though I have one in it.

Here's my code on Mouse click submit. [Note: NumberEmails.Value is a number
taken from a text box whos value is modifed by SpinButton]

Mind you I have replaced some string variables I hardcoding into the macro
as variables, so those have not been tested just yet, but I'd expect them to
work.

Private Sub SubmitButton_Click()

Set OutlookApp = CreateObject("Outlook.Application")
Dim objMail As Outlook.MailItem
Set objMail = OutlookApp.CreateItem(0)

Dim rcpt As Recipient

For i = 1 To NumberEmails.Value
Set objMail = Application.CreateItem(0)
If CB1.Value = True Then
Set rcpt = objMail.Recipients.Add(CB1.Tag)
If CB2.Value = True Then
Set rcpt = objMail.Recipients.Add(CB2.Tag)
If CB3.Value = True Then
Set rcpt = objMail.Recipients.Add(CB3.Tag)
If CB4.Value = True Then
Set rcpt = objMail.Recipients.Add(CB4.Tag)
If CB5.Value = True Then
Set rcpt = objMail.Recipients.Add(CB5.Tag)
If CB6.Value = True Then
Set rcpt = objMail.Recipients.Add(CB6.Tag)
If CB7.Value = True Then
Set rcpt = objMail.Recipients.Add(CB7.Tag)
If CB8.Value = True Then
Set rcpt = objMail.Recipients.Add(CB8.Tag)
If CB9.Value = True Then
Set rcpt = objMail.Recipients.Add(CB9.Tag)
If CB10.Value = True Then
Set rcpt = objMail.Recipients.Add(CB10.Tag)
If CB11.Value = True Then
Set rcpt = objMail.Recipients.Add(CB11.Tag)
If CB12.Value = True Then
Set rcpt = objMail.Recipients.Add(CB12.Tag)
If CB13.Value = True Then
Set rcpt = objMail.Recipients.Add(CB13.Tag)
If CB14.Value = True Then
Set rcpt = objMail.Recipients.Add(CB14.Tag)
If CB15.Value = True Then
Set rcpt = objMail.Recipients.Add(CB15.Tag)
If CB16.Value = True Then
Set rcpt = objMail.Recipients.Add(CB16.Tag)
If CB17.Value = True Then
Set rcpt = objMail.Recipients.Add(CB17.Tag)
If CB18.Value = True Then
Set rcpt = objMail.Recipients.Add(CB18.Tag)
If CB19.Value = True Then
Set rcpt = objMail.Recipients.Add(CB19.Tag)
If CB20.Value = True Then
Set rcpt = objMail.Recipients.Add(CB20.Tag)
Else: MsgBox ("No Emails Selected"), vbOKOnly

objMail.Subject = SubjectLine + CStr(i)
objMail.Body = "Test Message " + CStr(i)

Set myAtt = objMail.Attachments
myAtt.Add = AttachmentPath

objMail.Save
objMail.Send
Next

Set objMail = Nothing
Set myAtt = Nothing
Set rcpt = Nothing

End Sub
------
Private Sub SpinButton1_SpinDown()
If NumberEmails.Value = 1 Then NumberEmails.Value = 1 Else
NumberEmails.Value = NumberEmails.Value - 1
End Sub
------
Private Sub SpinButton1_SpinUp()
If NumberEmails.Value = 20 Then NumberEmails.Value = 20 Else
NumberEmails.Value = NumberEmails.Value + 1
End Sub
----------

  #3  
Old August 7th 09, 10:47 PM posted to microsoft.public.outlook.program_vba
mitch
external usenet poster
 
Posts: 47
Default Outlook VBA Form not finding FOR LOOP -- Error message

Got it working, had to also remove = from the myAtt.Add line.

"Mitch" wrote:

Found that my If statements were messing it up, wonder if there's a better
way to do this. A for loop to run through my 20 if statements ?

"Mitch" wrote:

I'm using Outlook 2003 SP3, using a VBA Form created throug Outlook, it
basically checks some checkboxes for a value of True, then adds an email
address. It works perfectly fine when I do it as a macro.

When I plug it into the form, my FOR Loop "NEXT" isn't finding the loop. I
get a Next neesda for loop even though I have one in it.

Here's my code on Mouse click submit. [Note: NumberEmails.Value is a number
taken from a text box whos value is modifed by SpinButton]

Mind you I have replaced some string variables I hardcoding into the macro
as variables, so those have not been tested just yet, but I'd expect them to
work.

Private Sub SubmitButton_Click()

Set OutlookApp = CreateObject("Outlook.Application")
Dim objMail As Outlook.MailItem
Set objMail = OutlookApp.CreateItem(0)

Dim rcpt As Recipient

For i = 1 To NumberEmails.Value
Set objMail = Application.CreateItem(0)
If CB1.Value = True Then
Set rcpt = objMail.Recipients.Add(CB1.Tag)
If CB2.Value = True Then
Set rcpt = objMail.Recipients.Add(CB2.Tag)
If CB3.Value = True Then
Set rcpt = objMail.Recipients.Add(CB3.Tag)
If CB4.Value = True Then
Set rcpt = objMail.Recipients.Add(CB4.Tag)
If CB5.Value = True Then
Set rcpt = objMail.Recipients.Add(CB5.Tag)
If CB6.Value = True Then
Set rcpt = objMail.Recipients.Add(CB6.Tag)
If CB7.Value = True Then
Set rcpt = objMail.Recipients.Add(CB7.Tag)
If CB8.Value = True Then
Set rcpt = objMail.Recipients.Add(CB8.Tag)
If CB9.Value = True Then
Set rcpt = objMail.Recipients.Add(CB9.Tag)
If CB10.Value = True Then
Set rcpt = objMail.Recipients.Add(CB10.Tag)
If CB11.Value = True Then
Set rcpt = objMail.Recipients.Add(CB11.Tag)
If CB12.Value = True Then
Set rcpt = objMail.Recipients.Add(CB12.Tag)
If CB13.Value = True Then
Set rcpt = objMail.Recipients.Add(CB13.Tag)
If CB14.Value = True Then
Set rcpt = objMail.Recipients.Add(CB14.Tag)
If CB15.Value = True Then
Set rcpt = objMail.Recipients.Add(CB15.Tag)
If CB16.Value = True Then
Set rcpt = objMail.Recipients.Add(CB16.Tag)
If CB17.Value = True Then
Set rcpt = objMail.Recipients.Add(CB17.Tag)
If CB18.Value = True Then
Set rcpt = objMail.Recipients.Add(CB18.Tag)
If CB19.Value = True Then
Set rcpt = objMail.Recipients.Add(CB19.Tag)
If CB20.Value = True Then
Set rcpt = objMail.Recipients.Add(CB20.Tag)
Else: MsgBox ("No Emails Selected"), vbOKOnly

objMail.Subject = SubjectLine + CStr(i)
objMail.Body = "Test Message " + CStr(i)

Set myAtt = objMail.Attachments
myAtt.Add = AttachmentPath

objMail.Save
objMail.Send
Next

Set objMail = Nothing
Set myAtt = Nothing
Set rcpt = Nothing

End Sub
------
Private Sub SpinButton1_SpinDown()
If NumberEmails.Value = 1 Then NumberEmails.Value = 1 Else
NumberEmails.Value = NumberEmails.Value - 1
End Sub
------
Private Sub SpinButton1_SpinUp()
If NumberEmails.Value = 20 Then NumberEmails.Value = 20 Else
NumberEmails.Value = NumberEmails.Value + 1
End Sub
----------

 




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
Outlook 2003 adding formulae to contact form gives error message o David Outlook - Using Forms 5 July 5th 07 02:26 PM
Outlook form error message [email protected] Outlook - Using Forms 1 November 21st 06 04:31 PM
my 3rd voting button in outlook form causes loop in tracking Kate Outlook - Using Forms 1 August 29th 06 12:41 PM
Outlook 2002 Test Message In Loop Jon Outlook - General Queries 1 July 21st 06 11:45 PM
Calendar: Error message - The form required to view this message Dave Kimani Outlook - Calandaring 0 July 18th 06 11:35 PM


All times are GMT +1. The time now is 01:38 PM.


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.