Using Outlook from Access

M

Miskacee

I'm trying to send emails from Access via Outlook. I am missing something
but can't seem to figure it out. I have several email addresses that I'd
like to use. The body/subject lines are the same.

Thank you!

My code is below:

Private Sub cmdOutlook_Click()

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'
With objEmail
'--------------
If emailaddress = False Then

Do Until emailaddress.EOF

.To = Me.emailaddress
.Subject = Me.txtSubject & " - " & Me.employee
.Body = Me.txtEmail
.Send

Loop

End With
 
D

Douglas J. Steele

What is emailaddress supposed to be? In one place, you're comparing it to
False. In another, you're using emailaddress.EOF inside a loop.

Not only that, but your loop doesn't seem to have any incrementation or move
statements in it.
 
M

Miskacee

Any help is greatly appreciated!!!!

this is the code I now have. I get an error:
'record has been moved or deleted'
I had it working earlier but didn't realize it and kept trying to figure it
out. Now I am brain dead and haven't a clue.

The emailaddress is an email address within the table. There are several.
It pulls the email address and then takes a text from a from.


Dim strsql As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tmp_Email")
'------------
Do While Not rst.EOF
With objEmail
.To = Me.emailaddress
.Subject = Me.txtSubject & " - " & Me.employee
.Body = Me.txtEmail
.Send

End With

rst.MoveNext
Loop
'----------
Debug.Print
Set rst = Nothing
 
D

Douglas J. Steele

Nothing in your code looks as though it should be generating the error
message you're describing. Is it possible that something else is changing
what's in tmp_Email while your code is running?
 
B

BeWyched

Hi

If emailaddress is a field in the tmp_Email table then,
.To = Me.emailaddress
should read
.To = rst!emailaddress

Cheers.

BW
 

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