help with modifying email code

N

neil.mcdonald

Hi,

I have a single form with an email button which emails a job report to
the address of the assigned plumber. I now need to do the same process
from a continuous form, running the code for each record displayed. I
guess I need some kind of loop, but I'm not sure how to implement it.

Can anybody give me any advice? I''ve posted my existing code below
(which I think I found on this forum!)

Thanks,

Neil

Private Sub cmdEmail_Click()

On Error GoTo Err_cmdEmail_Click


Dim strFileName As String, intFile As Integer, strLine As String,
strTemplate As String

strFileName = Environ("Temp") & "\rep_temp.txt"
strReportName = "JobEmail"
strTo = Forms!JobForm!EmaillAddress
strSubject = "Job No." & Forms!JobForm!JobID

If Len(Dir(strFileName)) > 0 Then
Kill strFileName
End If
DoCmd.OutputTo acOutputReport, strReportName, acFormatTXT, strFileName

intFile = FreeFile
Open strFileName For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strLine
strTemplate = strTemplate & vbCrLf & strLine
Loop
Close #intFile

DoCmd.SendObject acSendNoObject, "", acFormatTXT, strTo, , ,
strSubject, strBody & strTemplate, 0

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top