@2.W.M.C.:
I've no problem with using the public variables in the declaration section of my forms within dlookup.
In fact, I have one form where I store an SQL that is built based on user choices from an opening form... passing the values as openarg. This is a database that was in v2003 and now in v2010 (finally just bit the bullet and saved it as ACCDB as I wanted to remake the switchboard using the new navigation control).
I'd be willing to post an example DB with a very simple form that shows this to work.
@Soulspike:
I'm glad you have a solution; however, the way you built the criteria for the dlookup function is a pet-peeve
of mine. I don't blame you, I blame MS and every textbook author out there that shows programmers to build the string within the criteria parameter of the dlookup function, or within any function for that matter.
You have this huge string being built within the dlookup function... and I'll tell you now, the more complex the string - more likely it's going to choke on you when this function resolves - I found this out the hard way!
First pull that thing out of the function and assign it to a "strVAR" so that you can see the string. You use that strVAR instead within the function.
So you'll have something like:
- 'lead-in code omitted
-
strVAR= "[Location] = '" & [myShop] & _
-
"' AND [Removed_Date] > #" & _
-
DateAdd("h",-24,[myDate]) & _
-
"# and [Removed_Date] <= #" & _
-
[myDate] & "# AND [Executed]"
-
'
-
'place your stop or debug.print strVAR here.
-
'
-
strSOMETHING= DCount("[RN]","tbl_DIC", strVAR)
-
Now you can either debug print or place a stop command in the code to take a look at what you are actually getting back
I find that line 6 above to be interesting:
"# AND [Executed]"
That is not going to return the value from the control or record field [Executed], so your are getting that exact string appended after your date; thus you might have something like this for the resolved string:
"[Location] = 'exampleName' AND [Removed_Date] >#02/07/2013# AND [Removed_Date] <= #02/08/2013# AND [Executed]"
Is that what you wanted? I suspect that is where your #Name error is comming from.