Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agre with a comment, you should review the design for alternatives.</p> <p>In terms of the existing design there appear to be two options to me...<br> 1. Build up the query string in VBA, then execute it<br> 2. Use a CASE statement in the WHERE clause </p> <p>I admit I don't know Access's syntax, so here is SQL Server syntax for your inspiration...</p> <pre><code>WHERE CASE NumberOfCycles WHEN 1 THEN s1 WHEN 2 THEN s2 WHEN 3 THEN s3 WHEN 4 THEN s4 END IS NOT NULL </code></pre> <p>This, however, is not efficient as it is scanning every record and not able to make use of indexes, etc.</p> <p><strong>EDIT</strong></p> <p>Also, note that based on your example and actual question, if you ever have "NumberOfCycles = 3" but records where s3 and s4 are populated, both records are returned.</p> <p>I believe you would be advised to have a field "cycle" which describes the cycle at which the data was populated.</p> <pre><code> Cycle | Number Of Cycles | s1 | s2 | s3 | s4 1 | 4 | 0 | - | - | - 2 | 4 | 0 | 1 | - | - 3 | 4 | 0 | 1 | 0 | - 4 | 4 | 0 | 1 | 0 | 1 </code></pre> <p>Then you just need to search for "Cycle = NumberOfCycles"</p> <p><strong>EDIT</strong></p> <p>Apparently Access has a horrible SWITCH statement...</p> <pre><code>WHERE SWITCH( NumberOfCycles=1, s1, NumberOfCycles=2, s2, NumberOfCycles=3, s3, NumberOfCycles=4, s4 ) IS NOT NULL </code></pre> <p>Or you can expand to a horrible OR statement...</p> <pre><code>WHERE (NumberOfCycles=1 AND S1 IS NOT NULL) OR (NumberOfCycles=2 AND S2 IS NOT NULL) OR (NumberOfCycles=3 AND S3 IS NOT NULL) OR (NumberOfCycles=4 AND S4 IS NOT NULL) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload