title: Why am I getting "Enter Parameter Value" when running my MS Access query?
body: <p>In my query, I use the <code>IIF</code> function to assign either "Before" or "After" to a field named <code>BeforeOrAfter</code> using <code>AS</code>.</p>
  
  <p>When I run this query, however, the "Enter Parameter Value" dialog appears, requesting a value for <code>BeforeOrAfter</code>. If I remove <code>BeforeOrAfter DESC</code> from the <code>ORDER BY</code> clause, I don't get the dialog.</p>
  
  <p><strong>Here is the offending query:</strong></p>
  
  <pre><code>SELECT
      d.Scenario,
      e.Event,
      IIF(d.LogTime &lt; e.Time, 'Before','After') AS BeforeOrAfter,
      d.HeartRate
  FROM
      Data d INNER JOIN
      Events e ON d.Scenario = e.Scenario
  WHERE
      e.Include = Yes
  ORDER BY
      d.Scenario,
      e.Id,
      BeforeOrAfter DESC
  </code></pre>
  
  <p><strong>Question:</strong> Why is my <code>AS BeforeOrAfter</code> not being recognized by the <code>ORDER BY</code> clause? Why does it ask me to enter a parameter value for "BeforeOrAfter" when I run this query?</p>
  
  <p><strong>Note:</strong> I tried using brackets, single quotes, double quotes, etc., but none of that made any difference.</p>