Hello All...
What am I missing here. The below VBA Sql works in the QBE grid but pops an error of Item Not Found in the Collection when executed by a button on the form. I have 2 combo boxes on a form, and the user can enter search text in either of the fields but not both. When I place a Debug.Print strSQL I copy the output into a blank SQL query and it runs and provides the correct results.
Here is the VBA Sql:
strSQL = "SELECT tbl_AOG_Errors_Master.*, tbl_AOG_Errors_Master.Verification_Date, tbl_AOG_Errors_Master.Processor, tbl_AOG_Errors_Master.Manager, tbl_AOG_Errors_Master.Error_Y_N " & vbCrLf & _
"FROM tbl_AOG_Errors_Master " & vbCrLf & _
"WHERE (((tbl_AOG_Errors_Master.Verification_Date) Between #" & [Forms]![frm_ErrorEntry]![tb_SelectStartDate] & "# And #" & [Forms]![frm_ErrorEntry]![tb_SelectEndDate] & "#) AND ((tbl_AOG_Errors_Master.Processor)= '" & [Forms]![frm_ErrorEntry]![cb_SelectAnalyst] & "') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True)) OR (((tbl_AOG_Errors_Master.Verification_Date) Between #" & [Forms]![frm_ErrorEntry]![tb_SelectStartDate] & "# And #" & [Forms]![frm_ErrorEntry]![tb_SelectEndDate] & "#) AND ((tbl_AOG_Errors_Master.Manager)='" & [Forms]![frm_ErrorEntry]![cb_SelectManager] & "') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True));"
Here is the Debug.print output:
SELECT tbl_AOG_Errors_Master.*, tbl_AOG_Errors_Master.Verification_Date, tbl_AOG_Errors_Master.Processor, tbl_AOG_Errors_Master.Manager, tbl_AOG_Errors_Master.Error_Y_N
FROM tbl_AOG_Errors_Master
WHERE (((tbl_AOG_Errors_Master.Verification_Date) Between #10/23/2017# And #10/28/2017#) AND ((tbl_AOG_Errors_Master.Processor)= '') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True)) OR (((tbl_AOG_Errors_Master.Verification_Date) Between #10/23/2017# And #10/28/2017#) AND ((tbl_AOG_Errors_Master.Manager)='John Doe') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True));
What am I missing here. The below VBA Sql works in the QBE grid but pops an error of Item Not Found in the Collection when executed by a button on the form. I have 2 combo boxes on a form, and the user can enter search text in either of the fields but not both. When I place a Debug.Print strSQL I copy the output into a blank SQL query and it runs and provides the correct results.
Here is the VBA Sql:
strSQL = "SELECT tbl_AOG_Errors_Master.*, tbl_AOG_Errors_Master.Verification_Date, tbl_AOG_Errors_Master.Processor, tbl_AOG_Errors_Master.Manager, tbl_AOG_Errors_Master.Error_Y_N " & vbCrLf & _
"FROM tbl_AOG_Errors_Master " & vbCrLf & _
"WHERE (((tbl_AOG_Errors_Master.Verification_Date) Between #" & [Forms]![frm_ErrorEntry]![tb_SelectStartDate] & "# And #" & [Forms]![frm_ErrorEntry]![tb_SelectEndDate] & "#) AND ((tbl_AOG_Errors_Master.Processor)= '" & [Forms]![frm_ErrorEntry]![cb_SelectAnalyst] & "') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True)) OR (((tbl_AOG_Errors_Master.Verification_Date) Between #" & [Forms]![frm_ErrorEntry]![tb_SelectStartDate] & "# And #" & [Forms]![frm_ErrorEntry]![tb_SelectEndDate] & "#) AND ((tbl_AOG_Errors_Master.Manager)='" & [Forms]![frm_ErrorEntry]![cb_SelectManager] & "') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True));"
Here is the Debug.print output:
SELECT tbl_AOG_Errors_Master.*, tbl_AOG_Errors_Master.Verification_Date, tbl_AOG_Errors_Master.Processor, tbl_AOG_Errors_Master.Manager, tbl_AOG_Errors_Master.Error_Y_N
FROM tbl_AOG_Errors_Master
WHERE (((tbl_AOG_Errors_Master.Verification_Date) Between #10/23/2017# And #10/28/2017#) AND ((tbl_AOG_Errors_Master.Processor)= '') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True)) OR (((tbl_AOG_Errors_Master.Verification_Date) Between #10/23/2017# And #10/28/2017#) AND ((tbl_AOG_Errors_Master.Manager)='John Doe') AND ((tbl_AOG_Errors_Master.Error_Y_N)=True));