I am using Access 97 and I have this push button that retreives Emails from constituents in my database. I also have a search set up for the Constituents Street on the Query; which works fine when I try the Query. A run time error comes up when I hit the button.
Run time error '3061'
To few parameters. Expected 2.
The code is set up as a Module and is as follows...
Sub SendEmail()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strEmail As String
strEmail = ""
Set db = CurrentDb
Set qdf = db.QueryDefs("QryEmail"
'This should be the name of your query
Set rs = qdf.OpenRecordset
rs.MoveFirst
Do Until rs.EOF
If rs!email1 = "" Then
If rs!email2 = "" Then
Else
If strEmail = "" Then
strEmail = rs!email2
Else
strEmail = rs!email2 & "; " & strEmail
End If
End If
Else
If rs!email2 = "" Then
If strEmail = "" Then
strEmail = rs!email1
Else
strEmail = rs!email1 & "; " & strEmail
End If
Else
strEmail = rs!email1 & "; " & rs!email2 & "; " & strEmail
End If
End If
rs.MoveNext
Loop
Set lobjOutlook = CreateObject("Outlook.application"
Set lobjMail = lobjOutlook.CreateItem(0)
Let lobjMail.Subject = "TESTING E-Mail" 'Change the subject to anything you
'Let lobjMail.To = ""
'Let lobjMail.CC = ""
Let lobjMail.BCC = strEmail 'your list of email addresses
'Let lobjMail.HTMLBody = "Do you want the email to have a message?" 'Change
'the message of the email
Let lobjMail.Body = "Do you want the email to have a message?"
'Change the message of the email
lobjMail.Save 'This command will save the email as a draft
'lobjMail.Send 'I commented this out so you can see the email before it sends
End Sub
With this line highlighted -
Set rs = qdf.OpenRecordset
Does anyone know what the problem could be???
Thnaks in advance
Chris
Run time error '3061'
To few parameters. Expected 2.
The code is set up as a Module and is as follows...
Sub SendEmail()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strEmail As String
strEmail = ""
Set db = CurrentDb
Set qdf = db.QueryDefs("QryEmail"
Set rs = qdf.OpenRecordset
rs.MoveFirst
Do Until rs.EOF
If rs!email1 = "" Then
If rs!email2 = "" Then
Else
If strEmail = "" Then
strEmail = rs!email2
Else
strEmail = rs!email2 & "; " & strEmail
End If
End If
Else
If rs!email2 = "" Then
If strEmail = "" Then
strEmail = rs!email1
Else
strEmail = rs!email1 & "; " & strEmail
End If
Else
strEmail = rs!email1 & "; " & rs!email2 & "; " & strEmail
End If
End If
rs.MoveNext
Loop
Set lobjOutlook = CreateObject("Outlook.application"
Set lobjMail = lobjOutlook.CreateItem(0)
Let lobjMail.Subject = "TESTING E-Mail" 'Change the subject to anything you
'Let lobjMail.To = ""
'Let lobjMail.CC = ""
Let lobjMail.BCC = strEmail 'your list of email addresses
'Let lobjMail.HTMLBody = "Do you want the email to have a message?" 'Change
'the message of the email
Let lobjMail.Body = "Do you want the email to have a message?"
'Change the message of the email
lobjMail.Save 'This command will save the email as a draft
'lobjMail.Send 'I commented this out so you can see the email before it sends
End Sub
With this line highlighted -
Set rs = qdf.OpenRecordset
Does anyone know what the problem could be???
Thnaks in advance
Chris