title: MS Access query, IIF function is returning error as "No value given for one or more required parameters"
body: <p>I have Access query which does Union, group, get Maximum, Left Join and IIF(isNull) functions. 
  <a href="https://i.stack.imgur.com/84Ib8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/84Ib8.jpg" alt="enter image description here"></a>
  I have to union three subTables and group by column "mainid", get max-value from column "time" as "MaxSubTime" and mainid-column is filterd by mainTable.id.
  Then I am applying LEFT Join MainTable to Union-Group.
  If MaxSubTime is Null then i am applying the MainTable.endtime to MaxSubTime and getting it as "MaxMainTableEndTime".
  till here everything works fine.</p>
  
  <pre><code>string myQry = "SELECT MainTable.id, MainTable.sttime, IIF(IsNULL(a.MaxSubTime), MainTable.endtime, a.MaxSubTime) AS MaxMainTableEndTime 
              FROM (MainTable LEFT JOIN (SELECT mainid, MAX(SubTime) AS MaxSubTime 
              FROM (SELECT Sub_table_1.mainid, Sub_table_1.time AS SubTime FROM Sub_table_1 
                    UNION SELECT Sub_table_2.mainid, Sub_table_2.time AS SubTime Sub_table_2 
                    UNION SELECT Sub_table_3.mainid, Sub_table_3.time AS SubTime Sub_table_3 GROUP BY mainid) AS a ON a.mainid = MainTable.id)                       
              WHERE MaxMainTableEndTime &gt;= #" + DateTime.Now + "# ";
  </code></pre>
  
  <p>But when i filter the final query by "MaxMainTableEndTime", i am getting this error "No value given for one or more required parameters".
  Where i am doing mystake?</p>