Home > database >  DLookup returning True for some values, and False for others
DLookup returning True for some values, and False for others

Time:08-03

I am writing a program, and I need to be able to check whether a certain 'tag' exists, by looking at all the 'tags' in the column 'CowTagMain' of the 'CowTable' table.

The code I am using is, DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]") = Tag ... Where tag is a String, TagMain is the column, and MainTable, is the table I am fetching data from.

I am getting inconsistent results, when I try this with 18C, it returns true. While if I try this with 18, it returns false.

enter image description here

enter image description here

enter image description here

I would assume I am fundamentally misunderstanding how to use DLookup, but after searching the internet for hours I cannot understand what I am doing wrong. Even just pointing me in the right direction would be very appreciated! I am new to working with Access and VBA.

CodePudding user response:

The search criteria is not within the function WHERE CONDITION argument.
The field is text type so need apostrophe delimiters.

Consider:

If IsNull(DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]= '" & Tag & "'")) Then

  • Related