doctorswamp
Technical User
Hi all
Have working code that send data to Excel from a fixed query in Access. I'd like the query to ask for a date range but get an error.
This code works
****************
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim rst As Recordset
Dim iRow As Integer
Dim m As Integer
Set objXL = New Excel.Application
objXL.Visible = True
Set objWkb = objXL.Workbooks.Open("c:\timesheet.xlt")
Set objSht = objWkb.Worksheets("Timesheet")
iRow = 6
Set rst = CurrentDb.OpenRecordset("SELECT TimesheetHistory.HistoryDate," _
& "CompanyData.LTRef, CompanyData.Company, CompanyData.Contact," _
& "TimesheetHistory.Project, CompanyData.CNo, TimesheetHistory.Duration," _
& "TimesheetHistory.Adviser, TimesheetHistory.TimeSheetSource," _
& "TimesheetHistory.Type, TimesheetHistory.Reason, TimesheetHistory.Notes " _
& "FROM TimesheetHistory INNER JOIN CompanyData ON TimesheetHistory.LTRef = CompanyData.LTRef " _
& "WHERE (((TimesheetHistory.HistoryDate) Between #2/1/2006# And #2/28/2006#))" _
& "ORDER BY TimesheetHistory.HistoryDate;")
etc
****************
But when I change the WHERE condition to
Between [Start Date] And [End Date]
it returns
Run-time Error 3061
Too few parameters. Expected 2
Any ideas much appreciated.
Thanks
Have working code that send data to Excel from a fixed query in Access. I'd like the query to ask for a date range but get an error.
This code works
****************
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim rst As Recordset
Dim iRow As Integer
Dim m As Integer
Set objXL = New Excel.Application
objXL.Visible = True
Set objWkb = objXL.Workbooks.Open("c:\timesheet.xlt")
Set objSht = objWkb.Worksheets("Timesheet")
iRow = 6
Set rst = CurrentDb.OpenRecordset("SELECT TimesheetHistory.HistoryDate," _
& "CompanyData.LTRef, CompanyData.Company, CompanyData.Contact," _
& "TimesheetHistory.Project, CompanyData.CNo, TimesheetHistory.Duration," _
& "TimesheetHistory.Adviser, TimesheetHistory.TimeSheetSource," _
& "TimesheetHistory.Type, TimesheetHistory.Reason, TimesheetHistory.Notes " _
& "FROM TimesheetHistory INNER JOIN CompanyData ON TimesheetHistory.LTRef = CompanyData.LTRef " _
& "WHERE (((TimesheetHistory.HistoryDate) Between #2/1/2006# And #2/28/2006#))" _
& "ORDER BY TimesheetHistory.HistoryDate;")
etc
****************
But when I change the WHERE condition to
Between [Start Date] And [End Date]
it returns
Run-time Error 3061
Too few parameters. Expected 2
Any ideas much appreciated.
Thanks