英文:
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 "Query_Reagents_by_Mastername". I want to check if a value exists in the "Storage Location" field in that query. I'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
> Run-time error 2465: Microsoft Access can't find the field '|1' 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("*", "[Query_Reagents_by_Mastername]", "[SomeIdField] = 'R226-S01'")
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论