Variable Attachments in CDO/OL2K7?

C

corquando

Greetings, geniuses.

I have a standard CDO send sub that works just dandy, except for on
small detail.

For each email there will be a variable amount of attachments
anywhere from 1 to maybe 15 tops.

In the .With statement, I have this (all required statements beforehan
are present. I'm just omitting them here for space's sake.):


Code
-------------------

'looped for each email sent

With iMsg
Set .Configuration = iConf
.To = EML 'email address from database
.CC = ""
.BCC = ""
.From = "(e-mail address removed)"
.Subject = Subj 'defined in the db
.TextBody = strbody 'defined in the db
.AddAttachment (Atch1) 'AHA!! Here's the rub!!
.Send
End With

[\code]

How may I:

a) Loop around the .AddAttachment statement to add the required attachments, or
b) define a variable that would contain the necessary attachment values (Atch1), and have the statement needed only once, and
c) which is best or does it matter?

I've seen solutions for non-CDO programs and earlier OL versions but I'm wary since what I'm doing is different, and spending 2 or 3 hours trying to force something that won't work anyway is demoralizing.

Please ask for whatever additional and needed items I have mindlessly omitted, and thanks in advance!!
 
M

Michael Bauer [MVP - Outlook]

Whereever you get the filenames of the attachments from, loop through it,
for instance with:

for i=1 to count
....
next

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 24 Feb 2010 22:05:12 +0000 schrieb corquando:
Greetings, geniuses.

I have a standard CDO send sub that works just dandy, except for one
small detail.

For each email there will be a variable amount of attachments -
anywhere from 1 to maybe 15 tops.

In the .With statement, I have this (all required statements beforehand
are present. I'm just omitting them here for space's sake.):


Code:
--------------------

'looped for each email sent

With iMsg
Set .Configuration = iConf
.To = EML 'email address from database
.CC = ""
.BCC = ""
.From = "(e-mail address removed)"
.Subject = Subj 'defined in the db
.TextBody = strbody 'defined in the db
.AddAttachment (Atch1) 'AHA!! Here's the rub!!
.Send
End With

[\code]

How may I:

a) Loop around the .AddAttachment statement to add the required attachments, or
b) define a variable that would contain the necessary attachment values
(Atch1), and have the statement needed only once, and
c) which is best or does it matter?

I've seen solutions for non-CDO programs and earlier OL versions but I'm
wary since what I'm doing is different, and spending 2 or 3 hours trying to
force something that won't work anyway is demoralizing.
Please ask for whatever additional and needed items I have mindlessly
omitted, and thanks in advance!!!
 
C

corquando

'Michael Bauer [MVP - Outlook said:
;341979']Whereever you get the filenames of the attachments from, loo
through it,
for instance with:

for i=1 to count
....
next

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


Herr Bauer:

Vielen dank fur die Hilfe . . .

And it accomplished the attaching quite well. The next issue, though
and it should be simple (I just don't know where to look) is to clea
the Atch1 variable so I don't accumulate attachments on each successiv
send:
Code
-------------------For i = 2 To z
If Range("A" + CStr(i)) = "" Then GoTo 27
Subj = Range("C" + CStr(i))
EML = Range("E" + CStr(i))
ID = Range("B" + CStr(i))
Call TextBody(i, strbody)
y = 0
With iMsg
Set .Configuration = iConf
.To = EML
.CC = ""
.BCC = ""
.From = "(e-mail address removed)"
.Subject = Subj
.TextBody = strbody
Do While Range("B" + CStr(i + y)) = ID
DocName = Range("D" + CStr(i + y))
Atch1 = "C:\Huge\Medium\Small\" + DocName + ".pdf"
.AddAttachment (Atch1): y = y + 1
Loop
.Send
End With
27 Next

[\code]

Each successive email has all the attachments that previous emails have had plus the new ones. I am sure it's an elementary command, but CDO statement catalogs are hard to come by.

And I know it's simple - I'm good at simple.

Noch einmal danke sehr
 
M

Michael Bauer [MVP - Outlook]

The variable is cleared, or overwritten respectively, automatically as soon
as you write the next file name into it. However, atch1="" will also do it.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Fri, 26 Feb 2010 21:39:48 +0000 schrieb corquando:
'Michael Bauer [MVP - Outlook said:
;341979']Whereever you get the filenames of the attachments from, loop
through it,
for instance with:

for i=1 to count
....
next

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


Herr Bauer:

Vielen dank fur die Hilfe . . .

And it accomplished the attaching quite well. The next issue, though,
and it should be simple (I just don't know where to look) is to clear
the Atch1 variable so I don't accumulate attachments on each successive
send:
Code:
--------------------For i = 2 To z
If Range("A" + CStr(i)) = "" Then GoTo 27
Subj = Range("C" + CStr(i))
EML = Range("E" + CStr(i))
ID = Range("B" + CStr(i))
Call TextBody(i, strbody)
y = 0
With iMsg
Set .Configuration = iConf
.To = EML
.CC = ""
.BCC = ""
.From = "(e-mail address removed)"
.Subject = Subj
.TextBody = strbody
Do While Range("B" + CStr(i + y)) = ID
DocName = Range("D" + CStr(i + y))
Atch1 = "C:\Huge\Medium\Small\" + DocName + ".pdf"
.AddAttachment (Atch1): y = y + 1
Loop
.Send
End With
27 Next

[\code]

Each successive email has all the attachments that previous emails
have had plus the new ones. I am sure it's an elementary command, but CDO
statement catalogs are hard to come by.
 
C

corquando

Alrighty, then . . .

I'd tried that, but it still 'stacked up' the attachments; then
noticed that I had only one CDO session opened, and was looping throug
the records within that one session. Evidently the session wa
remembering the attachments and sending them as they piled up.

What I finally did (using the 'Atch="" ' command) was to loop throug
the records, opening and then closing a CDO session for each email. I
still went just as fast, so evidently that's acceptable.

Thanks and best regards
 

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