sending e-mail to filtered result

ronnroz

Registered User.
Local time
Today, 09:03
Joined
Nov 30, 2004
Messages
15
Happy New Year to ALL!

I am trying to e-mail from a form that displays filtered result, but having trouble. Could someone please guide me?

I am using DoCmd.SendObject (a routine that I found in a newsgroup). This routine works fine when I am sending it to all the recipients, but not to filtered recipients. The form shows filtered result, but I am not being able to use the command to only send to filtered recipients. Following is the code:


Private Sub cmdGenerateList_Click()
'Create Email list from the appropriate query and open Outlook with those addresses in the cc: field

Dim db As Database, rs As Recordset, sql As String, emailTo As String, txtEmailList As String


On Error GoTo Err_cmdGenerateList_Click

Set db = CurrentDb()

emailTo = ""
sql = "select EmailName from qInd_info "
Set rs = db.OpenRecordset(sql)




Do Until rs.EOF
If Not IsNull(rs!EmailName) Then
'build up email addresses separated by a semicolon
emailTo = emailTo & rs!EmailName & "; "
End If
rs.MoveNext
Loop


'Remove the last semicolon
If Right(emailTo, 2) = "; " Then
emailTo = Left(emailTo, Len(emailTo) - 2)
End If

' Me.txtEmailList = emailTo

'Create the message with the recipients in the BCC: field
' DoCmd.SendObject acSendNoObject, , , , , emailTo
DoCmd.SendObject acSendNoObject, , , , emailTo

Exit_cmdGenerateList_Click:
Exit Sub

Err_cmdGenerateList_Click:

Select Case Err.Number
Case 2501
Resume Next
Case Else
MsgBox Err.Description
Resume Exit_cmdGenerateList_Click

End Select

End Sub
 
Ron

Presuming that qInd_info is the query that does the filtering that is the likely source of the problem . Bit difficult to advise without seeing that query. Perhaps the filtered query is returning no results which would mean that the recordset would be empty therfore no emails!
 
Thanks JGC31 for replying.

What do you think I should do then? I tried replacing the query name with the original table name, but same result. And as opposed to no e-mails, it actually shows all the e-mails, that means the filter is not being applied. However, the filter IS being applied to the form that displays all the information, but as soon as I press the button to send e-mail, my cc: box gets populated with all the e-mails in a table, rather than the e-mails of those filtered individuals.

Please help me out. If you think I am not on the right track, show me another way of doing that. Thank you all for your time.
 

Users who are viewing this thread

Back
Top Bottom