Single Record to Email from Form

Megawisdumb

Registered User.
Local time
Today, 04:33
Joined
Apr 18, 2002
Messages
17
Not having much luck taking a few fields from the record displayed in my form to an email with a command button. No attachments needed, just some basic text although with a couple of data fields from the form. I did get it to pull the first record by using the following:

Function Email()

Dim db As database
Dim recSupps As DAO.recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strOrder As String

Set db = CurrentDb()
Set recSupps = db.OpenRecordset("qryOpen")

' add a greeting to the order
strOrder = "Dear " & recSupps("Username") & _
vbCrLf & vbCrLf & _
"The following ticket was logged with the Help Desk on:" & recSupps("Autointime") & _
vbCrLf & vbCrLf & _
recSupps("Detail") & _
vbCrLf & vbCrLf & _
"TICKET STATUS: CLOSED on xx/xx/02" & _
vbCrLf & vbCrLf & _
"If you find the issue is still unresolved, please let me know" & _
vbCrLf & vbCrLf & _
"Phil"

' now create the mail message to the supplier
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.Subject = "Help Ticket #1" & recSupps("Id")
.Body = strOrder
.Display
End With

' tidy up
recSupps.Close
Set recSupps = Nothing
Set objOutlook = Nothing
Set objMessage = Nothing

End Function
 
The reason why you are getting the first record is that you are opening a query as a recordset. This opens to the first record of the query. Since you never move through the recordset it will only do the one record.

If you are on a form that has the data you want to send, just use the form.

If your query was suppose to limit itself to the current record then you will need to review the query and find out why it is not limiting the recordset.
 
So my Set recSupps reference would point to the form? Me.frmOpen ??
 

Users who are viewing this thread

Back
Top Bottom