error 3061

D

David Sullivan

HI I am using the following code , but when
it is run I am getting the following error

Runtime error 3061

Two few parameters , expected 3

am receiving the error from the following line of code
Set rs = db.OpenRecordset("qryEmail", dbOpenDynaset)

which is contained in the following procedure


Public Sub email()
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("qryEmail", dbOpenDynaset)

Set oApp = New Outlook.Application

Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
'Loop through recordset to add recipients
rs.MoveFirst
Do While Not rs.EOF
If Len(Trim(rs!email)) > 0 Then
Set objOutlookRecip = .Recipients.Add(rs!email)
objOutlookRecip.Type = olTo
End If
rs.MoveNext
Loop
.Subject = "Test subject"
.Body = "Your text message here."
.Save
.Send
End With

rs.Close
Set rs = Nothing
End Sub
this part of the code where it does not seem to be
passing the three parameters across to VBA. It should be
picking up the three parameters from the following query

SELECT Contacts.CompanyName, Contacts.Title, Contacts.EmailName,
Contacts.[Job Type]
FROM Job_Type INNER JOIN Contacts ON Job_Type.[Job Type] = Contacts.[Job
Type]
WHERE (((Contacts.Title) Is Null) AND ((Job_Type.[Job Type]) Is Null))
OR(((Contacts.Title) Like "*" & [Enter any character in the Job Title to
search by: ] & "*") AND ((Job_Type.[JobType]) Between
[Job_Type].[StartValue]
And [Job_Type].[EndValue]));

I hope someone can help as I am a complete Novice with
VB and am thinking I might be out of my depth here
 
C

Cheryl Fischer

Your post appears to be exactly the same as the one from Evelyn Robertson in
"microsoft.public.internet" ...

This code also fails in my tests when I use a parameter query. As an
alternative, use your parameter query as the Record Source for a form.
Then replace this:
Set rs = db.OpenRecordset("qryEmail", dbOpenDynaset)

with this:

Set rs = Me.RecordsetClone



--
Cheryl Fischer
Law/Sys Associates
Houston, TX

David Sullivan said:
HI I am using the following code , but when
it is run I am getting the following error

Runtime error 3061

Two few parameters , expected 3

am receiving the error from the following line of code
Set rs = db.OpenRecordset("qryEmail", dbOpenDynaset)

which is contained in the following procedure


Public Sub email()
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("qryEmail", dbOpenDynaset)

Set oApp = New Outlook.Application

Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
'Loop through recordset to add recipients
rs.MoveFirst
Do While Not rs.EOF
If Len(Trim(rs!email)) > 0 Then
Set objOutlookRecip = .Recipients.Add(rs!email)
objOutlookRecip.Type = olTo
End If
rs.MoveNext
Loop
.Subject = "Test subject"
.Body = "Your text message here."
.Save
.Send
End With

rs.Close
Set rs = Nothing
End Sub
this part of the code where it does not seem to be
passing the three parameters across to VBA. It should be
picking up the three parameters from the following query

SELECT Contacts.CompanyName, Contacts.Title, Contacts.EmailName,
Contacts.[Job Type]
FROM Job_Type INNER JOIN Contacts ON Job_Type.[Job Type] = Contacts.[Job
Type]
WHERE (((Contacts.Title) Is Null) AND ((Job_Type.[Job Type]) Is Null))
OR(((Contacts.Title) Like "*" & [Enter any character in the Job Title to
search by: ] & "*") AND ((Job_Type.[JobType]) Between
[Job_Type].[StartValue]
And [Job_Type].[EndValue]));

I hope someone can help as I am a complete Novice with
VB and am thinking I might be out of my depth here
 

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

Similar Threads


Top