I have the following code that is designed to insert the results of a query into a separate table, preparing them for export to Excel. This is done on a form which uses combo boxes. The filters are in the "WhereStatement." It works great until I attempt to include this part: Nz(Me.txtTargetDate.value,0) AS TargetDate. This is my attempt at targeting an unbound textbox that holds a date on the parent forum. It results in an error "Run-time error '3061': Too few parameters. Expected 1." I have tried other various ways to modify this line and only get other types of errors. What am I doing wrong here?
Code:
Option Compare Database
Option Explicit
Private WhereStatement As String
Private Sub btnExcelExport_Click()
Dim db As DAO.Database
Dim sSQL As String
Set db = CurrentDb
sSQL = "INSERT INTO tblExcelExport (ExcelExport_BackdaterID, ExcelExport_Project0IDfk, ExcelExport_Project1IDfk, ExcelExport_Project2IDfk, ExcelExport_Task, ExcelExport_StatDate, " _
& "ExcelExport_DueDate, ExcelExport_SnoozeUntil, ExcelExport_DaysAhead_ReminderTime, ExcelExport_OwnerIDfk, ExcelExport_IncludeInExport, ExcelExport_DueDate_DaysPrior,ExcelExport_EventDate) " _
& "SELECT tblBackdater.BackdaterID, tblBackdater.Backdater_Project0IDfk, tblBackdater.Backdater_Project1IDfk, tblBackdater.Backdater_Project2IDfk, tblBackdater.Backdater_Task, " _
& "tblBackdater.DaysPriorIDfk_StatDate, tblBackdater.DaysPriorIDfk_DueDate, tblBackdater.DaysPriorIDfk_SnoozeUntil, tblBackdater.Backdater_DaysAhead_ReminderTime, tblBackdater.Backdater_OwnerIDfk, " _
& "tblBackdater.Backdater_IncludeInExport, lkqDaysPrior.DaysPrior_Number, Nz(Me.txtTargetDate.value,0) AS TargetDate FROM qryBackdater " _
& WhereStatement & "ORDER BY lkqDaysPrior.DaysPrior_Number ASC;"
db.Execute sSQL, dbFailOnError