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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send email to query fields

Status
Not open for further replies.

auerd

Technical User
Oct 5, 2003
5
US
Access 2003
When I click a button on my form I would like it to email to all recepients
that are in a query. Query is qLookupNotifyNewProj.
SQL
SELECT DISTINCT t41ContactsMSP.MSPContactEmail
FROM (tblVersion LEFT JOIN t41ContactsMSP ON tblVersion.UserID =
t41ContactsMSP.MSPContactUserID) LEFT JOIN t040Project ON t41ContactsMSP.
MSPContactID = t040Project.ContactPMID
WHERE (((tblVersion.NewProj)="Notify of New Project")) OR (((t040Project.
ContactPMID)=[Forms]![f30ProjMaster]![f40ProjectMain].[Form]![ContactPMID]));

I have the same code to email another report using a similar Query and it
works fine.
SQL to the query that I can email with
SELECT DISTINCT t41ContactsMSP.MSPContactEmail
FROM tblVersion INNER JOIN t41ContactsMSP ON tblVersion.UserID =
t41ContactsMSP.MSPContactUserID
WHERE (((tblVersion.NewProj)="Can Create New Project"));

I am getting error
'runtime error -2147217900 (80040e14) invalid SQL statement; expected Delete,
Insert, Procedure, Select or Update

Why does it work with one query and not the other? How can I fix this?

Here is my code.

'Verify email address is not blank then send email in acFormatSNP
If IsNull(DLookup("[MSPContactEmail]", "qLookupNotifyNewProj")) Then
MsgBox "Email address is blank, see database admin to add email," _
& vbCr & vbCr & " and try again to submit.", vbOKOnly, "Missing Email"
Exit Sub

Else
MsgBox "New Project Notification has been sent.", vbOKOnly, "Notification
Sent"

Dim rs As New ADODB.Recordset
Dim strEmail As String

'runtime error -2147217900 (80040e14) invalid SQL statement; expected Delete,
Insert, Procedure, Select or Update
rs.Open "qLookupNotifyNewProj", CurrentProject.Connection, adOpenDynamic,
adLockOptimistic 'Open ADO recordset with the name of the table or query
holding the email addresses

strEmail = "" ''Clear strEmail Variable
Do While Not rs.EOF
strEmail = strEmail & rs!MSPContactEmail & ";" ''Build email string...
MSPContactEmail is the name of the field in the table/query specified earlier
which holds the email address

rs.MoveNext
Loop

'Send email using SendObject
On Error Resume Next
DoCmd.SendObject acSendReport, "rEmailNewProjectNotify", acFormatSNP,
strEmail, , , "FYI Project Creation", _
"This new project has been created in the Project Information database (PIdb)
", False

'Close established references...clean up code
rs.Close
Set rs = Nothing
End If

Thank you for your help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top