Hi All,
I am trying to use the UNION ALL syntax in a vba DoCmd.RunSQL function.
The following syntax works fine if I use it in a query design window, but I need the code to be in vba. When I run the following code I get an error that says "Syntax error (missing operator) in query expression".
Any clues?
Cheers
Foxy
I am trying to use the UNION ALL syntax in a vba DoCmd.RunSQL function.
The following syntax works fine if I use it in a query design window, but I need the code to be in vba. When I run the following code I get an error that says "Syntax error (missing operator) in query expression".
Code:
DoCmd.RunSQL "INSERT INTO tblTemp_CloseSummScores_Parent (cypd_per_id, caf_id, close_date, question, improvement) " & _
"SELECT tblChild.cypd_per_id, tblClosure.caf_id, tblClosure.close_date, '1. Health',summ_par_score_a_then-summ_par_score_a_now " & _
"FROM tblChild INNER JOIN (tblCAF INNER JOIN tblClosure ON tblCAF.caf_ID = tblClosure.caf_id) ON tblChild.child_ID = tblCAF.child_id " & _
"WHERE tblClosure.summ_par_score_a_then IS NOT NULL OR tblClosure.summ_par_score_b_then IS NOT NULL OR tblClosure.summ_par_score_c_then IS NOT NULL " & _
"OR tblClosure.summ_par_score_d_then IS NOT NULL OR tblClosure.summ_par_score_e_then IS NOT NULL OR tblClosure.summ_par_score_f_then IS NOT NULL " & _
"OR tblClosure.summ_par_score_a_now IS NOT NULL OR tblClosure.summ_par_score_b_now IS NOT NULL OR tblClosure.summ_par_score_c_now IS NOT NULL " & _
"OR tblClosure.summ_par_score_d_now IS NOT NULL OR tblClosure.summ_par_score_e_now IS NOT NULL OR tblClosure.summ_par_score_f_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_a_then IS NOT NULL OR tblClosure.summ_chil_score_b_then IS NOT NULL OR tblClosure.summ_chil_score_c_then IS NOT NULL " & _
"OR tblClosure.summ_chil_score_d_then IS NOT NULL OR tblClosure.summ_chil_score_e_then IS NOT NULL OR tblClosure.summ_chil_score_f_then IS NOT NULL " & _
"OR tblClosure.summ_chil_score_g_then IS NOT NULL OR tblClosure.summ_chil_score_a_now IS NOT NULL OR tblClosure.summ_chil_score_b_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_c_now IS NOT NULL OR tblClosure.summ_chil_score_d_now IS NOT NULL OR tblClosure.summ_chil_score_e_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_f_now IS NOT NULL OR tblClosure.summ_chil_score_g_now IS NOT NULL " & _
"UNION ALL "& _
"SELECT tblChild.cypd_per_id, tblClosure.caf_id, tblClosure.close_date, '2. Safety',summ_par_score_b_then-summ_par_score_b_now " & _
"FROM tblChild INNER JOIN (tblCAF INNER JOIN tblClosure ON tblCAF.caf_ID = tblClosure.caf_id) ON tblChild.child_ID = tblCAF.child_id " & _
"WHERE tblClosure.summ_par_score_a_then IS NOT NULL OR tblClosure.summ_par_score_b_then IS NOT NULL OR tblClosure.summ_par_score_c_then IS NOT NULL " & _
"OR tblClosure.summ_par_score_d_then IS NOT NULL OR tblClosure.summ_par_score_e_then IS NOT NULL OR tblClosure.summ_par_score_f_then IS NOT NULL " & _
"OR tblClosure.summ_par_score_a_now IS NOT NULL OR tblClosure.summ_par_score_b_now IS NOT NULL OR tblClosure.summ_par_score_c_now IS NOT NULL " & _
"OR tblClosure.summ_par_score_d_now IS NOT NULL OR tblClosure.summ_par_score_e_now IS NOT NULL OR tblClosure.summ_par_score_f_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_a_then IS NOT NULL OR tblClosure.summ_chil_score_b_then IS NOT NULL OR tblClosure.summ_chil_score_c_then IS NOT NULL " & _
"OR tblClosure.summ_chil_score_d_then IS NOT NULL OR tblClosure.summ_chil_score_e_then IS NOT NULL OR tblClosure.summ_chil_score_f_then IS NOT NULL " & _
"OR tblClosure.summ_chil_score_g_then IS NOT NULL OR tblClosure.summ_chil_score_a_now IS NOT NULL OR tblClosure.summ_chil_score_b_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_c_now IS NOT NULL OR tblClosure.summ_chil_score_d_now IS NOT NULL OR tblClosure.summ_chil_score_e_now IS NOT NULL " & _
"OR tblClosure.summ_chil_score_f_now IS NOT NULL OR tblClosure.summ_chil_score_g_now IS NOT NULL"
Any clues?
Cheers
Foxy