The following code will allow you to specify the location for saving a
report.
You can call the function from a custom button on a button bar or a custom
menu item.
In the button's On Action property enter
funOutputReportToXL
Or enter
=funOutputReportToXL()
Public Function funOutputReportToXL()
'Save the currently selected report to Excel Output
'Called from a button bar or menu item.
Dim strObjName As String
Dim intState As Integer
Dim intCurrObjType As Integer
On Error GoTo ERROR_Trap
intCurrObjType = Application.CurrentObjectType 'Get TYPE OF last Report,
'Form, Table, Module, Query, or Macro with cursor
strObjName = Application.CurrentObjectName 'Get object's name
intState = SysCmd(acSysCmdGetObjectState, intCurrObjType, strObjName)
If intCurrObjType = acReport Then
If intState = acObjStateOpen Then 'Report is open (naturally)
'Leaving 4th argument blank causes Access to ask for an output file
name
DoCmd.OutputTo acOutputReport, strObjName, acFormatXLS, , False
End If
Else
MsgBox "Please display a report to output to an excel document.", ,
"Preview a Report"
End If
Exit_Trap:
Exit Function
ERROR_Trap:
If Err.Number = 2501 Then
'Cancel pressed
Else
MsgBox Err.Number & ": " & Err.Description
End If
Resume Exit_Trap
End Function
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..