Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if a Variable exists in a query

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Use the correct syntax, like:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading