Missing Output Command

hootie318

Registered User.
Local time
Today, 00:36
Joined
Oct 28, 2003
Messages
130
I am missing something. I am trying to output a single record into an email. I have it outputting the whole table. Can someone review and possibly push me in the right direction.

Private Sub Command65_Click()
Dim stDocName As String
Dim sFilter As String
Dim strPath As String
Dim strTemp As String
Dim strBody As String
Dim strEmail As String

strPath = DLookup("TextPath", "tbl_PathInfo")
strEmail = DLookup("EmailAddress", "tbl_EmailAddresses")
sFilter = "CallLogID = Forms!ServiceLog!CallLogID"
Dim EmailApp, NameSpace, EmailSend As Object

DoCmd.OutputTo acReport, "Email", acFormatTXT, strPath

Open strPath For Input As #1
Do Until EOF(1)
Line Input #1, strTemp
strBody = strBody & strTemp & vbCrLf
Loop
Close #1
Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.getNameSpace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

EmailSend.TO = strEmail
EmailSend.subject = [SearchName]
EmailSend.Display
EmailSend.Body = strBody

Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing

Kill strPath

End Sub
 
I'm not sure why you are outputting the records to a text file then reading the text file. Why not just open a recordset and grab whatever record you need?

But it looks like your problem is the DO Until... Loop
statement.

It will continue to LOOP until it reaches the end of the file, which is probably why you are getting all the records instead of just 1.

Evan
 
You have set your StrFilter but it is not used in the code to select the required record.

Alternatively you could generate a report with the selected record and then send it in a snapshot format or other formats using the following code

Dim stDocName As String
Dim strEmail As String
Dim email_title as String

strEmail = DLookup("EmailAddress", "tbl_EmailAddresses")
strDocName = "NAME OF YOUR REPORT"
email_title = "EMAIL SUBJECT LINE"
DoCmd.SendObject acReport, strDocName, "SnapshotFormat(*.snp)", "", "", "", email_title, "", True, ""
 

Users who are viewing this thread

Back
Top Bottom