检查查询中是否存在一个变量。

huangapple go评论56阅读模式
英文:

Check if a Variable exists in a query

问题

我有一个查询名为“Query_Reagents_by_Mastername”。我想检查该查询中“Storage Location”字段是否存在某个值。我已经使用了DCount函数来实现:

``` VBA
S01Count = DCount("Storage Location", "Query_Reagents_by_Mastername", ["R226-S01"])
If S01Count > 0 Then
Debug.Print ("存在")
Else
Debug.Print("不存在")
End If

但每次运行时我都会收到以下错误:

运行时错误 2465:Microsoft Access 找不到您表达式中引用的字段 '|1'。

有人知道如何解决这个问题吗?

我尝试过直接在if语句中包含DCount表达式,但结果是同样的错误。


<details>
<summary>英文:</summary>

I have a query names &quot;Query_Reagents_by_Mastername&quot;. I want to check if a value exists in the &quot;Storage Location&quot; field in that query. I&#39;ve used the DCount function to do so:


S01Count = DCount("Storage Location", "Query_Reagents_by_Mastername", ["R226-S01"])
If S01Count > 0 Then
Debug.Print ("Exists")
Else
Debug.Print("Does not exist")
End If

But whenever I run it I get the following error
&gt; Run-time error 2465: Microsoft Access can&#39;t find the field &#39;|1&#39; referred to in your expression.

Does anybody know how I can fix this?

I have tried including the DCount expression directly in the if statement but this results in the same error

</details>


# 答案1
**得分**: 0

使用正确的语法,如下:

    S01Count = DCount("*", "[Query_Reagents_by_Mastername]", "[SomeIdField] = 'R226-S01'")

<details>
<summary>英文:</summary>

Use the correct syntax, like:

    S01Count = DCount(&quot;*&quot;, &quot;[Query_Reagents_by_Mastername]&quot;, &quot;[SomeIdField] = &#39;R226-S01&#39;&quot;)

</details>



huangapple
  • 本文由 发表于 2023年5月11日 18:24:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定