Hi
I'm trying to export the results of a filtered subform into excel. I can export the entire subform ok, but have not managed to export only the filtered records. I'm trying to get the code below to work, BUT when I run it I receive an error message:
3129
Invalid SQL Statement; Expected 'Delete', 'Insert', 'Procedure', 'Select', Or 'Update
Within the code below:
"MySubFrm.RecordSource" is returning the correct recordsource name (A query named: qryCmtsDetail)
Really not sure what I am doing wrong. Would appreciate any help . Thx for looking!!!!!
I'm trying to export the results of a filtered subform into excel. I can export the entire subform ok, but have not managed to export only the filtered records. I'm trying to get the code below to work, BUT when I run it I receive an error message:
3129
Invalid SQL Statement; Expected 'Delete', 'Insert', 'Procedure', 'Select', Or 'Update
Within the code below:
"MySubFrm.RecordSource" is returning the correct recordsource name (A query named: qryCmtsDetail)
Really not sure what I am doing wrong. Would appreciate any help . Thx for looking!!!!!
Code:
On Error GoTo errHandler
Dim MyMainFrm As Form
Dim MySubFrm As Form
Set MyMainFrm = Forms!frmCmtsDetail
Set MySubFrm = MyMainFrm.Controls("ctrlCmtsDetail").Form
Dim qdf As QueryDef
DoCmd.DeleteObject acQuery, "qryTemp"
MsgBox MySubFrm.RecordSource
Set qdf = CurrentDb.CreateQueryDef("qryTemp", MySubFrm.RecordSource)
MsgBox qdf
DoCmd.OutputTo acOutputQuery, "qryTemp", acFormatXLS, "C:\Commitments.xls", True
exitHandler:
Exit Sub
errHandler:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
Resume exitHandler
End If