By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,344 Members | 1,853 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,344 IT Pros & Developers. It's quick & easy.

repeatedly creating object - bad?

P: n/a
like this:

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset(strSql)
rst.MoveFirst
Do While Not rst.EOF
Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
.To = rst.Fields("Email1")
.Subject = "test from Access from Mike"
.Body = "don't worry, it's not a virus"
.Send
End With
Set oMailItem = Nothing
rst.MoveNext
Loop

Mike
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Mike MacSween" <mi***********************@btinternet.com> wrote in
news:40***********************@news.aaisp.net.uk:
like this:

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset(strSql)
rst.MoveFirst
Do While Not rst.EOF
Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
.To = rst.Fields("Email1")
.Subject = "test from Access from Mike"
.Body = "don't worry, it's not a virus"
.Send
End With
Set oMailItem = Nothing
rst.MoveNext
Loop


Why set to Nothing when you're immediately going to set it to
something different at the top of the loop? You would then put a Set
to Nothing after the loop terminates.

What's your question?

Oh, I see.

The question is: do you *need* to recreate it or just change the
properties.

Set oMailItem = oOutlook.CreateItem(olMailItem)
Do While Not rst.EOF
With oMailItem
.To = rst.Fields("Email1")
.Subject = "test from Access from Mike"
.Body = "don't worry, it's not a virus"
.Send
End With
rst.MoveNext
Loop
Set oMailItem = Nothing

The answer to the question entirely depends on how Outlook deals
with the message. Does it get a different MessageID? I don't know
what interaction there is between Outlook and Exchange server in
those terms. I also don't know exactly where MessageIDs are
generated (I've always assumed at your local outbound SMTP server).

Of course, if you're generating the same email message to numerous
people, you could use CC or BCC to send a single message to multiple
recipients. Of course, that also may end up getting your email
classified as spam (which, to some people, it may be). Some ISPs
won't accept an email with more than 20 or 25 recipients, so you
might have to break them down in groups.

In any event, I don't know why there's be any reason to recreate the
object -- you could just re-use it. But you'd have to see if there
were any downsides to that.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #2

P: n/a
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.74...
"Mike MacSween" <mi***********************@btinternet.com> wrote in
news:40***********************@news.aaisp.net.uk:
like this:

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset(strSql)
rst.MoveFirst
Do While Not rst.EOF
Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
.To = rst.Fields("Email1")
.Subject = "test from Access from Mike"
.Body = "don't worry, it's not a virus"
.Send
End With
Set oMailItem = Nothing
rst.MoveNext
Loop
Why set to Nothing when you're immediately going to set it to
something different at the top of the loop? You would then put a Set
to Nothing after the loop terminates.


Thanks David

Yes, you're right I don' need the

Set oMailItem = Nothing
but I do need the
Set oMailItem = oOutlook.CreateItem(olMailItem)
at the top of the loop

Otherwise on the 2nd time through the loop I get

'The Item has been moved or deleted' on the line

To = rst.Fields("Email1")

I'm thinking that the .send makes the mailItem unavailable (which makes
sense) unless it's recreated.
What's your question?

Oh, I see.

The question is: do you *need* to recreate it or just change the
properties.
It seems I need to recreate it. As above. I think I just put a set to
nothing in there to match the createObject above it.
Set oMailItem = oOutlook.CreateItem(olMailItem)
Do While Not rst.EOF
With oMailItem
.To = rst.Fields("Email1")
.Subject = "test from Access from Mike"
.Body = "don't worry, it's not a virus"
.Send
End With
rst.MoveNext
Loop
Set oMailItem = Nothing

The answer to the question entirely depends on how Outlook deals
with the message. Does it get a different MessageID? I don't know
what interaction there is between Outlook and Exchange server in
those terms. I also don't know exactly where MessageIDs are
generated (I've always assumed at your local outbound SMTP server).

Of course, if you're generating the same email message to numerous
people, you could use CC or BCC to send a single message to multiple
recipients.
I'm not. This isn't finished, but inside that loop there'll be another one
preparing the body text for each recipient, which will be different.
Of course, that also may end up getting your email
classified as spam (which, to some people, it may be).
what, 40 emails giving booking details to casually employed staff?
In any event, I don't know why there's be any reason to recreate the
object -- you could just re-use it. But you'd have to see if there
were any downsides to that.


As above.

Cheers, Mike
Nov 12 '05 #3

P: n/a
"Mike MacSween" <mi***********************@btinternet.com> wrote in
news:40***********************@news.aaisp.net.uk:
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.74...

Of course, that also may end up getting your email
classified as spam (which, to some people, it may be).


what, 40 emails giving booking details to casually employed staff?


Spam is in the eye of the beholder.

And as more and more people use Bayesian filtering, any email could
get classified as spam, if it is sufficiently similar to the
messages that the recipient has already classified as spam.

If you don't know about Bayesian spam filtering, I suggest you read:

http://www.paulgraham.com/better.html

as well as any number of other fascinating articles on Paul Graham's
website.

I'm using the SAProxy implementation of SpamAssassin, and have been
training the Bayesian filtering since early January (I started off
training it with a body of 10K spam messages and 5K non-spam), and
it's amazingly accurate, with almost no false positives (about 3
since January). Occasionally I get misses, maybe 5 or 10 per week
(out of over 1,000 messages received each week, 90% of which are
spam).

I highly recommend that anyone who is having spam problems
investigate one of the Bayesian solutions, such as SpamBayes or
SAProxy (though the free version is no longer available) or an email
client like Thunderbird that includes built-in Bayesian filtering.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #4

P: n/a
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
Spam is in the eye of the beholder.
I thought it meant Unsolicited Commercial Email.
If you don't know about Bayesian spam filtering, I suggest you read:


Yes, I use the SpamBayes add in for Outlook. It seems pretty good. I'd still
prefer something that added white and black lists. Some of the early false
junk suspects I got were from this client. She wasn't offering to transfer
$30,000,000 (thirty million US dollars) from an account in Lagos, or even
describing in great detail what she wanted to do with parts of my anatomy
(more's the pity!), just something like 'test email' was enough. Still, at
least it went into the Junk suspects folder. Even so it would be nice to
have the facility to always treat email from certain accounts as good.

Personally I'm hoping 'the industry' sorts it out in the next couple of
years.

Mike
Nov 12 '05 #5

P: n/a
"Mike MacSween" <mi***********************@btinternet.com> wrote:
Personally I'm hoping 'the industry' sorts it out in the next couple of
years.


Between Sender Permitted Framework, SPF http://spf.pobox.com/ and MS's CallerID
http://www.microsoft.com/mscorp/twc/privacy/spam.mspx this should help with a great
deal of the spam and virusses.

Both work by telling the recipient email servers which email servers are authorized,
by IP address, to send mail from your domain.

Virusses will now have to go through mail servers to be sent which means that your
ISP or email server can now scan for viruses on outgoing email. And shut you down.

Spams will now have to be associated with domains. Yes, the spammers can purchase
throwaway domains and flood the market. Which they are already doing in the body of
some spams I see.

But no longer will they be able to use "zombies" to send their spams. Zombies being
computers who have been hijacked by virusses and port scans and are being used by the
spammers and hackers.

Thus the efforts of various anti-spam groups can now be targetted towards explicit
domain names and it will be several orders of magnitude easier to deal with the
spammers.

I already have SPF implemented for my domains. Once MS has some testing pages
available I'll be putting those on my domains as well.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #6

P: n/a
"Mike MacSween" <mi***********************@btinternet.com> wrote in
news:40***********************@news.aaisp.net.uk:
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
Spam is in the eye of the beholder.
I thought it meant Unsolicited Commercial Email.


It means "email I don't want."

And that's as it should be.
If you don't know about Bayesian spam filtering, I suggest you
read:


Yes, I use the SpamBayes add in for Outlook. It seems pretty good.
I'd still prefer something that added white and black lists. . . .


SpamAssassin has whitelists/blacklists.
. . . Some
of the early false junk suspects I got were from this client. She
wasn't offering to transfer $30,000,000 (thirty million US
dollars) from an account in Lagos, or even describing in great
detail what she wanted to do with parts of my anatomy (more's the
pity!), just something like 'test email' was enough. Still, at
least it went into the Junk suspects folder. Even so it would be
nice to have the facility to always treat email from certain
accounts as good.
In my experience, the single characteristic of an email message most
strongly correlated with spamminess is HTML encoding.
Personally I'm hoping 'the industry' sorts it out in the next
couple of years.


It's already done, so far as I can tell. You just need tools that
present to you all the latest capabilities.

And, of course, you really shouldn't be using Outlook for anything
at all related to email.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.