PMFJI,
The syntax is
expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)
it looks like you want to output a query, so the DoCmd statement would look like
Code:
DoCmd.OutputTo acOutputQuery, reportname, acFormatXLS, theFilePath, True
To output a report, you could also try
Code:
DoCmd.OutputTo acOutputReport, reportname, acFormatXLS, theFilePath, True
Code:
Private Sub Command9_Click()
Dim reportname As String
Dim theFilePath As String
reportname = "qryPrintrecord"
theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\Output\"
theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"
Debug.Print theFilePath
DoCmd.OutputTo acOutputQuery, reportname, acFormatXLS, theFilePath, True
MsgBox "Look on your desktop for the report."
End Sub