Export Subform to Excel and open

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

I have a Subform on the main form that I can export to Excel, but I
would like for that data to open after the output command. behind the
click properties, I have:

Private Sub exportexcel_Click()
DoCmd.OutputTo acOutputForm, "frm_subform", acFormatXLS, _
strPath & "C:\\ServerData.xls" ', AutoStart:=-1

OpenExcelFile ("C:\\ServerData.xls")
Dim objXL As Object

On Error Resume Next

Set objXL = GetObject(, "Excel.Application")
Set objXL = GetObject(strPathToFile)

objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True
End Sub

I am getting a "sub or function not defined" error.

Thanks in advance!
 
I have a Subform on the main form that I can export to Excel, but I
would like for that data to open after the output command.  behind the
click properties, I have:

Private Sub exportexcel_Click()
DoCmd.OutputTo acOutputForm, "frm_subform", acFormatXLS, _
strPath & "C:\\ServerData.xls" ', AutoStart:=-1

OpenExcelFile ("C:\\ServerData.xls")
Dim objXL As Object

On Error Resume Next

Set objXL = GetObject(, "Excel.Application")
Set objXL = GetObject(strPathToFile)

objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True
End Sub

I am getting a "sub or function not defined" error.

Thanks in advance!

Nevermind... I had an error in the code, and was code-heavy. This is
simply the code:

Private Sub exportexcel_Click()
DoCmd.OutputTo acOutputForm, "frm_subform", acFormatXLS, _
strPath & "C:\\ServerData.xls" , True

This will save the file to your local machine, and open the results
up.

Thanks.
 
Back
Top