I watched a YouTube video to help me get the code below, and it seems to work okay, except I need to filter the records based on a form control. I tried entering it as a criteria in the query; however, it returned a "Too few parameters: Expected 1" error. I thought it might work better to filter it in the vba code itself, but the section I added in and attempted to run locked up access and in the end didn't filter it. Any ideas?
___________
Private Sub btnExporttoExcel_Click()
Dim XL As Excel.Application
Dim wbTarget As Workbook
Dim qdfEA As QueryDef
Dim rsEA As Recordset
Set qdfEA = CurrentDb.QueryDefs("qryExpenseActual_ExcelExport" )
Set rsEA = qdfEA.OpenRecordset()
With rsEA
.Filter = "[EventsID]=" & Me.EventsID
End With
Set XL = CreateObject("Excel.application")
Set wbTarget = XL.Workbooks.Open("C:\Destination.xlsx")
wbTarget.Worksheets("ExpenseActual").Cells.ClearCo ntents
wbTarget.Worksheets("ExpenseActual").Cells(1, 1).CopyFromRecordset rsEA
wbTarget.Save