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 OutputTo to generate individual HTML filenames

Status
Not open for further replies.

louchem

Technical User
Jun 17, 2003
2
US
Newbie here...so be gentle. :)

I have a problem that seems like it should be simple, but I am stumped. I've checked the FAQ and searched around but have yet to find a solution.

I have a report that I want to export to HTML. I want each record to be exported to it's own HTML file. I've been able to get this to work by using the &quot;Force New Page&quot; selection and the Export function. But what I get are filenames like <reportname>Page1.html, <reportname>Page2.html, <reportname>Page3.html, etc. I want to have each HTML file named using the Name value in each record. So, I want the filenames to look like this johnsmith.html, adamjones.html, stevesmith.html, etc.

So, I explored the OutputTo function in VBA and tried this code based upon various helpfiles:

DoCmd.OutputTo acOutputReport, &quot;<reportname>&quot;, acFormatHTML, &quot;c:\&quot; & Reports!<reportname>!Name.Text & &quot;.html&quot;

It got me almost where I wanted to be. The output it gave me used the name from the first record and appended Page1, Page2, etc...so I got johnsmithPage1.html, johnsmithPage2.html, etc.

But, I don't know where to go from here. I'm a complete novice using VBA, so I hope I'm just missing some simple command or designation.

Any help would be appreciated!
 
Here is a way of exporting reports to separate files.
First set some global variables to control the contents of the report.
Code:
Public usefilter As Boolean
Public Namefilter As Variant

Behind an export button you will need to create some code to loop through the names for the reports you create. Do this by opening a recordset and looping through it.
Code:
Private Sub Command8_Click()
Dim rstNames As Object
Dim ReportPath As String
Dim fileid As String
Dim OutputFileName As String

If MsgBox("Are you sure you want to export files?", vbYesNo) = vbNo Then
    Exit Sub
End If

ReportPath = "c:\"
fileid = "." & Format(Me!FilterDate, "MMYY") & ".html"

Set rstNames = CurrentDb.OpenRecordset("tblNames")

With rstNames
If (Not .EOF) And (Not .BOF) Then
    .MoveFirst
    While Not .EOF
        usefilter = True
        Managerfilter = Nz(!ProjectManager, "")
        If Managerfilter = "" Then
            OutputFileName = ReportPath & "No Name" & fileid
        Else
            OutputFileName = ReportPath & !Name & fileid
        End If
        DoCmd.OutputTo acOutputReport, "rptOutput", acFormatHTML, OutputFileName
        usefilter = False
        .MoveNext
    Wend
Else
    'errormessage
End If
.Close
End With
Set rstNames = Nothing

End Sub


Put this code into your report to set the name filter before the report is exported.
Code:
Private Sub Report_Open(Cancel As Integer)
If usefilter Then
    Me.FilterOn = True
    Me.Filter = "Nz([Name],'') = '" & Namefilter & "'"
Else
    Me.FilterOn = False
    Me.Filter = ""
End If
End Sub

HTH
Peter
 
Hey I think this is exactly what I am trying to do. Would you be able to repost the code in a more generic form?

Even if not,

What are you using the following for?

ReportPath = "c:\"
fileid = "." & Format(Me!FilterDate, "MMYY") & ".html"

Any help is appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top