I'm trying to run the below SQL string in VBA. However, when I do I receive a data type mismatch error. I have also tried using #" & dtPayrollMonth & "# for the date variable, but received the same error. I also tried surrounding "Corp" in "", but that didn't work. Thanks in advance.
Code:
mySQL = "INSERT INTO tblPayroll_Data ( PayrollAmt, Trailing12Payroll, Department, PayrollMonth ) " & _
"SELECT Sum(tblPayroll_Import.[" & arrFields(i) & "]) AS [SumOf" & arrFields(i) & "], Sum(tblPayroll_Import.[Trailing 12 Mos#]) " & _
"AS [SumOfTrailing 12 Mos#], 'Corp' AS Department, Cdate(" & dtPayrollMonth & ") AS PayrollMonth " & _
"FROM tblPayroll_Import;"
db.Execute mySQL, dbFailOnError