-----Original Message-----
Henk said:
Can some one help me.
In my database is an datafield a Email adress.
I want to select with a querie al the items with an email
adress. Then export the query in MS Outlook as an "Send
to" item.
I've tried everything but i cannot get it rigt.
Is there someone out there who can help me?
Here's some working code to send the results of a query to Outlook, with an
attachment, if one exists. If you uncomment the.Send line, it will send it
directly off without opening it first:
Function EmailBrokers(strTo As String, strSubject _
As String, Optional varMsg As Variant, Optional varPath As String =
"")
' ©Arvin Meyer 1999-2003.
' Permission to use is granted if copyright notice is left intact.
' Permisssion is denied for use with unsolicited commercial email
' Set reference to Outlook
On Error GoTo Errhandler
Dim strBCC As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim objOutl As Outlook.Application
Dim objEml As Outlook.MailItem
Dim i As Integer
Set db = CurrentDb
Set qdf = db.QueryDefs!qryEmail
qdf.Parameters(0) = [Forms]![frmEmail]![txtStartDate]
qdf.Parameters(1) = [Forms]![frmEmail]![txtEndDate]
Set rst = qdf.OpenRecordset()
Set objOutl = CreateObject("Outlook.application")
Set objEml = objOutl.createItem(olMailitem)
With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With
For i = 1 To rst.RecordCount
If Len(rst!EmailAddress) > 0 Then
strBCC = strBCC & rst!EmailAddress & ";"
End If
rst.MoveNext
Next i
strBCC = Left$(strBCC, Len(strBCC) - 1)
'Debug.Print strBCC
With objEml
.To = strTo
.BCC = strBCC
.Subject = strSubject
If Not IsNull(varMsg) Then
.Body = varMsg
End If
If Len(varPath & vbNullString) > 0 Then
.Attachments.Add varPath
End If
.Display
' .Send
End With
ExitHere:
Set objOutl = Nothing
Set objEml = Nothing
Set rst = Nothing
Set db = Nothing
Exit Function
Errhandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.554 / Virus Database: 346 - Release Date: 12/20/2003
.