probably formatpdf needs to be acFormatPDF.
probably formatpdf needs to be acFormatPDF.
Sorry it's taken so long to get back to this. I am still getting the error Too Few parameters, expected 2. I will highlight the line that it happens.
Code:(sorry I still don't have a code icon) Dim rsEmail As DAO.Recordset Dim strEmail As String Dim strSubject As String Dim strContactName As String Set db = CurrentDb Set qDef = db.QueryDefs("EmployeeEmailQuery") Set rsEmail = qDef.OpenRecordset Do While Not rsEmail.EOF strEmail = rsEmail.Fields("emailaddress").Value 'strContactName = rsEmail.Fields("fullName").Value DoCmd.SendObject acSendReport, "schedule", acFormatPDF, strEmail, , "" & Me!Subject, "" & Me!Greeting, "" & Me!Message 'DDoCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , , """" & Me!Subject & """", """" & Me!Greeting & """", """" & Me!Message & """"oCmd.SendObject acSendReport, "schedule", formatpdf, strEmail, , , """" & Me!Subject & """", """" & Me!Greeting & """", """" & Me!Message & """" ' False rsEmail.MoveNext Loop Set rsEmail = Nothing Set qDef = Nothing Set db = Nothing MsgBox "Emails have been sent"
I have just a couple of questions. What are the criteria in your query EmployeeEmailQuery I'm assuming it has 2 criteria that are based on a reference to a form?
If so you *may* be able to solve the parameter prompt by putting parameters in your query
so let's say in your query you have the criteria [Forms]![frmTest]![SearchField1], create a parameter in your query with the exact same syntax and define the data type that you expect for that field/parameter.
If EmployeeEmailQuery is a crosstab you may have some other difficulties with it.
Secondly
DoCmd.SendObject acSendReport, "schedule", acFormatPDF, strEmail, , "" & Me!Subject, "" & Me!Greeting, "" & Me!Message
You don't need the "" marks in your subject and greeting you should be able to do this:
DoCmd.SendObject acSendReport, "schedule", acFormatPDF, strEmail, , Me!Subject, Me!Greeting, Me!Message
what was the purpose of putting in the "" & in each one of these?
rpeare - using "" & fieldname handles nulls automatically without any logic.
Gina - after all the code put /code in square brackets.
try this:
And get rid of all the comments and duplicates in that area of the code. You don't need to keep copies of things that didn't work.Code:DoCmd.SendObject acSendReport, "schedule", acformatPDF, strEmail, , , "" & Me!Subject, "" & Me!Greeting, "" & Me!Message
Yes Dal but why would you want those values to be null, you'd just be inserting an empty string, that's what I'm getting at, what would be the purpose of creating, essentially, a blank email if those values were null. Wouldn't it be better to prevent the email from being generated at all if any of those items were missing and notify the user so they could fix whatever's missing. Regardless of how you handle nulls the parameter issue is the part that needs fixing and I'm wondering if it's a crosstab or just a regular select query.
I see. Yes, it would seem like, once she gets the minimum functionality
she needs, that some additional error trapping would be a good idea for
the subject and message text boxes.