I really dislike that all of the examples show to use the function with the where clause built in place as it make the programmer's life more difficult.
Why you might ask, because you cannot check how the string is actually resolving!
Instead, I suggest a slight modification to make troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.
So to use your code:
- DIM strSQL as string
-
strSQL = "[AssetTag1] = Form.[AssetTag1] And [Active]<>0"
-
'
-
'now you can insert a debug print here for troubleshooting
-
' - press <ctrl><g> to open the immediate window
-
' - you can now cut and paste this information for review!
-
'
-
debug.print "Your criteria = " & strSQL
-
'
-
'now use the string in your code:
-
(DLookUp("[AssetTag1]", _
-
"[tblEmployeeInfo]", _
-
strSQL )) _
-
is not null
-
Your where string also looks a bit off...
- "[AssetTag1] = Form.[AssetTag1] And [Active]<>0"
Did you intend (I've stepped this here just to put emphases on the data being pulled from the form and added grouping to help with the logic flow):
- "([AssetTag1] = " & _
-
Form.[AssetTag1] & _
-
") And (" & _
-
[Active] & "<>0)"
so that the string would return values from the form?
If you will make these little changes and post back the resolved string we can help you tweak the code.
The other thing of note, it looks as if you are using the
DLookup()
directly in the if..then conditional which is fine in and of itself; however, once again it can make trouble shooting difficult. I would personally assign you function to another variable and test against that in your conditional, I usually use the
NZ()
around
DLookup()
functions and return something logical rather than a potential zero-length string (aka null) or zero when I need to be sure that there is no useable result being returned.
as for why your code is hanging... I suspect it has to do with your function not returning anything useable...
Place a
STOP
command at the start of your code and step thru it using [F8]... you're most likely in a loop; however, without that code, we won't be able to explicitly solve that problemwhich