Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using SendObject method with a template file 1

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
US
I am trying to send a MS 97 query via email. I am using an ASP template file to format the output of the query. The code I current have does work but the problem I have is that the template file has a heading and My boss would like to to input the vendor name of the reciepent in the heading of the template file. At this time I do not know of a way to include this information in the code (or is it is at all possible) since I am looping thru a recordset. any help would be appreciated. here is my current test code.

While Not rst.EOF
' send mail.
DoCmd.SendObject acSendQuery, _
"TEST_REPORT", _
acFormatHTML, rst("email"), , , _
"This is only a test", _
vbCrLf & vbCrLf & _
"TEST TEST TEST" & vbCrLf & _
"--------------" & vbCrLf & _
"This is a test, False, & _
"C:\physician_Rpt.asp"
Wend
 
Well...you could take the asp file and rewrite it on the fly. First, make sure that you have just one line like:

<head>Whatever you have</head>

in your asp template.
Then paste the following code in a module:

Sub ChangeHeader(YourLine As String)
Dim intfreefile As Integer
Dim mycounter As Long
intfreefile = FreeFile
ReDim myarray(0)
Dim myvalue

'First, open the file to read it
Open &quot;C:\physician_Rpt.asp&quot; For Input As #intfreefile
Do Until EOF(intfreefile)

'check each line if it builds the header
Line Input #intfreefile, myvalue
If InStr(myvalue, &quot;<head>&quot;) <> 0 Then
'this is the header, so let's change it
myvalue = &quot;<head>&quot; & YourLine & &quot;</head>&quot;
End If
'store the value in the array
myarray(UBound(myarray, 1)) = myvalue
'make room for the next line
ReDim Preserve myarray(UBound(myarray, 1) + 1)
Loop
Close #intfreefile

'Now open the file for replacement
intfreefile = FreeFile
'Now get the new file from the array:
Open &quot;C:\physician_Rpt.asp&quot; For Output As #intfreefile
'Write each line from the array to the file
For mycounter = 0 To UBound(myarray, 1) - 1
Print #intfreefile, myarray(mycounter)
Next
Close #intfreefile
'get rid of the array
Erase myarray
'That's all folks
End Sub

Your final code should look like:

While Not rst.EOF
'build your header:
NewHeader = rst(VendorName) & &quot; whatever &quot;
Call ChangeHeader(NewHeader)

' send mail.
DoCmd.SendObject acSendQuery, _
&quot;TEST_REPORT&quot;, _
acFormatHTML, rst(&quot;email&quot;), , , _
&quot;This is only a test&quot;, _
vbCrLf & vbCrLf & _
&quot;TEST TEST TEST&quot; & vbCrLf & _
&quot;--------------&quot; & vbCrLf & _
&quot;This is a test, False, & _
&quot;C:\physician_Rpt.asp&quot;
Wend

Good luck

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top