开发者

Access query if blank run another query

开发者 https://www.devze.com 2023-02-21 23:42 出处:网络
I am trying to run an Access Report in which the value of a field depends on a query. I have a subreport for this.

I am trying to run an Access Report in which the value of a field depends on a query. I have a subreport for this.

If the value is not found in the first query it must run another until the value is found. How can I accomplish this in Acce开发者_Python百科ss 2003 +. Is doing this in VBA using DAO or ADO the best option.


One possibility would be to UNION ALL your queries and use ordering to pick the first found value (assuming you are talking about a reasonable and finite number of queries). For example:

SELECT TOP 1 MyVal
FROM (SELECT 1 AS Seq, Field1 AS MyVal FROM MyQuery1 UNION ALL
      SELECT 2 AS Seq, Field1 AS MyVal FROM MyQuery2 UNION ALL
      SELECT 3 AS Seq, Field7 AS MyVal FROM MyQuery3)
ORDER BY Seq, MyVal
0

精彩评论

暂无评论...
验证码 换一张
取 消