Emailing from Access

A

APH

Hi Evryone

I am trying to set up so that I can send emails straight from Access. Using
W2k and Access 2000 on this machine.

My code is as follows:
Public Sub Email()
Dim db As Database
Dim emailrecs As Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strMessage As String
Dim strSQL As String

Set db = CurrentDb()
Set emailrecs = db.OpenRecordset("qryFollowUp")

While Not emailrecs.EOF
strMessage = "Dear " & emailrecs("Title") & " " & ("Surname") & _
vbCrLf & vbCrFl & _
"test text test text"
If Not IsNull(emailrecs("tblContacts.email")) Then
With objMessage
.to = (e-mail address removed)
.Subject = "test message test message"
.body = strMessage
.send
End With
End If
emailrecs.MoveNext
Wend

emailrecs.Close
Set emailrecs = Nothing
Set objOutlook = Nothing
Set objMessage = Nothing

End Sub

I amgetting an error message at the line:

Set emailrecs = db.OpenRecordset("qryFollowUp") -telling me that I have
error 3061, Too few parameters, Exprected 1.

Can someone tell me what that means, apart from the fact that I have it
wrong!

Thanks

Alex
 
K

Kagsy

Alex

It looks as though you have a parameter in the query. Try
running the query and there should be a prompt for a
value. The best way to code this would be to create a
QueryDef and append the parameter, and execute the
QueryDef.

Kagsy
 
A

APH

Kagsy

Yes you are perfectly correct I will try what you suggest

Also apologies - I think someone else in my office has just posted the same
question

Alex
 
A

APH

Kagsy

Just thinking about what you have suggested. yes there is a parameter in
the query, and that effectively filters the records. Once the query has
been completed and the records displayed, I then press a button to send the
emails. Since i have already selected the records, and i going about this
in the wrong way, by opening the recordset again in my code?

Sorry to ask what is possibly a basic question but still a novice with
Access.

Alex
 

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