Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Email push button!!!

Status
Not open for further replies.

Cricker

Technical User
Sep 11, 2002
31
CA
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
 
It looks like the problem is with your query, not your code.

When you open the query through the database window does it ask you for a couple of parameters? I'm not sure, but I don't think you can use a parameter query for this type of operation.

If you need to collect those parameters from users, make a form that has a couple of controls to gather that info and then build the sql manually in your code, based on the sql in the query.

If you need help with that part, post back with the complete sql from your query and the data types of the two fields for which you need parameters.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
The database is for the use of 2 people. They need to find everyone with an email who lives in a certain area and on a street. Here is the SQL...

SELECT ConstituentTable.ConstTableID, ConstituentTable.email1, ConstituentTable.email2, TBLIssueCategory.Issue, TBLsubIssues.SubName
FROM TBLIssueCategory INNER JOIN (TBLsubIssues INNER JOIN (ConstituentTable INNER JOIN TBLControl ON ConstituentTable.ConstTableID = TBLControl.ConstTableID) ON TBLsubIssues.SubIssueID = TBLControl.SubIssueID) ON TBLIssueCategory.IssuesID = TBLControl.IssuesID
WHERE (((ConstituentTable.email1)>"1") AND ((TBLIssueCategory.Issue)=[Main]) AND ((TBLsubIssues.SubName)=));

 
OK, I would change
(ConstituentTable.email1)>"1")
to
Not(isnull(ConstituentTable.email1))

and I would do as I said above--make a form to collect the Issue and Subname, which appear to be the parameters it's expecting.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top