E-mailing CERTAIN fields from a query (1 Viewer)

jimday1982

Registered User.
Local time
Today, 03:35
Joined
May 13, 2004
Messages
81
I'm not quite sure where to start with this one...I have a query that returns data similar to what you see below:

id--------desc-------- fax-----------------phone-------------email---------------code
123 stove 444-444-4444 444-444-4444 blah@aol.com abc
456 phone 333-333-3333 444-444-4444 blah@aol.com abc
789 pen 222-222-2222 444-444-4444 me@me.com lmnop
355 paper 111-111-1111 444-444-4444 me2@me2.com lmnop2

Somehow, I need to e-mail only the corresponding records to the designated email address...for instance, me@me.com should only get the 3rd line of data in an e-mail. blah@aol.com should get the first line and the second line.

I know it's a matter of looping through the recordset, but I am really stuck. If anyone could provide any guidance, I'd REALLY appreciate it!
 

sando

Registered User.
Local time
Today, 17:35
Joined
Jul 7, 2004
Messages
25
this will help you get started.

I can only get this to email one set of records. But at least it's a start. If you work out how to get it to send more than one let me know.

-------------------------------------

Dim rst As DAO.Recordset
Dim qdf As QueryDef
Dim prm As DAO.Parameter
Dim oOutlook As Outlook.Application
Dim oMessage As Outlook.MailItem

Set qdf = CodeDb.QueryDefs("Queryname")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)

Next prm

Set rst = qdf.OpenRecordset()

Set oOutlook = CreateObject("Outlook.Application")
Set oMessage = oOutlook.CreateItem(olMailItem)

Do Until rst.EOF


With oMessage
.Importance = olImportanceHigh
.to = rst!
.Subject = " "
' vbCrLf is a carriage return
.Body = " " & rst![desc] & vbCrLf & rst![fax]& vbCrLf & vbCrLf & rst![phone] & vbCrLf & "Kind Regards."

.Send

End With

rst.MoveNext


Loop
 

Users who are viewing this thread

Top Bottom