Visual Basic Reference

Template Property

See Also    Example    Applies To

Returns or sets the HTML template to use in exporting a report.

Syntax

object.Template [=string]

The Template property syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
string Optional. The header and/or footer code to be used.

Remarks

If no template is specified when invoking the ExportReport method, a default template appropriate to the report type will be used. Four default types are provided:

  • HTML template

  • UTF-8 encoded HTML

  • Text

  • Unicode text

You can print the default templates for use as a starting point in creating your own template by using the code below:

   Dim i As Integer
   For i = 1 To rptNwind.ExportFormats.Count
      Debug.Print "Template " & i
      Debug.Print rptNwind.ExportFormats(i).Template
      Debug.Print
   Next i

You can create your own templates using HTML tags such as <HTML>, <HEAD>, <TITLE>, <BODY> and their requisite closing tags. To specify where the body of the report should be placed, use the Visual Basic constant rptTagBody. For example, the code fragment below places the body of the report between the <BODY> tags:

Dim strTemplateBody As String
strTemplateBody = _
"<BODY>" & vbCrLf & _
rptTagBody & vbCrLf & _
"</BODY>"

Similarly, you can use the constant rptTagTitle to place the title (as determined by the Title property) anywhere in the template. The fragment below places the title just above the body:

Dim strTemplateBodyAndTitle As String
strTemplateBodyAndTitle = _
rptTagTitle & vbCrLf & _
"<BODY>" & vbCrLf & _
rptTagBody & vbCrLf & _
"</BODY>"

Accordingly, the default template for Text export consists simply of the rptTagBody constant. Thus you could create a simple text template that prefaces the report with the author's name, followed by the rptTagBody constant, as shown in the example below:

   Dim strTemplate As String
   strTemplate = _
   "Author: John Smith" & vbCrLf & _
   rptTagBody