DLookup with three criteria

Lkwdmntr

Registered User.
Local time
Yesterday, 20:13
Joined
Jul 10, 2019
Messages
311
Can someone tell me what's wrong with this? These are so confusing. I never know when to put the quotes and when not to.

Code:
DLookup("[WeeklyPlanID]", "tblWeeklyPlans", "[UserID] = " & Me.txtUserID & " AND [Loop] = '" & loopNum & "' AND [WeekNumber] = '" & weekNum & "'")

I'm getting a data type mismatch in criteria expression error 3464

The UserID field is a Long in the DB and the other two are Integers.
 
What data types are loopnum and weeknum?
 
I got it. Just played around with it some more. Ended up with this.

Code:
DLookup("[WeeklyPlanID]", "tblWeeklyPlans", "[UserID] = " & Me.txtUserID & " AND [Loop] = " & loopNum & " AND [WeekNumber] = " & weekNum)

Thanks anyway!
 
I got it. Just played around with it some more. Ended up with this.

Code:
DLookup("[WeeklyPlanID]", "tblWeeklyPlans", "[UserID] = " & Me.txtUserID & " AND [Loop] = " & loopNum & " AND [WeekNumber] = " & weekNum)

Thanks anyway!
Congratulations! Numeric data types don't need quote delimiters. Good luck with your project.
 
Do yourself a favour.
Put all the criteria into a string variable and use that.

That also enables you to Debug.Print strCriteria so you can see if the syntax is correct.
I generally use single quotes for text unless the text also has a single quote in it, then I *think* it is triple double quotes. :unsure:
Dates need to be surrounded with # and numerics are not surrounded with anything.
 
I tried that and still didn't work. Getting a syntax error (missing operator) in query expression '[UserIDFK] = AND [StatusFK] <> '

DCount("[WeeklyPlanID]", "tblWeeklyPlans", "[UserIDFK] = " & lngUserID & " AND [StatusFK] <> " & status)
 
I tried that and still didn't work. Getting a syntax error (missing operator) in query expression '[UserIDFK] = AND [StatusFK] <> '

DCount("[WeeklyPlanID]", "tblWeeklyPlans", "[UserIDFK] = " & lngUserID & " AND [StatusFK] <> " & status)
In that case, you could try.

Code:
DCount("*", "tblWeeklyPlans", "[UserIDFK] = " & Nz(lngUserID,0) & " AND [StatusFK] <> " & Nz(status,0))
 
Please do Not post the same question multiple times.
 
In that case, you could try.

Code:
DCount("*", "tblWeeklyPlans", "[UserIDFK] = " & Nz(lngUserID,0) & " AND [StatusFK] <> " & Nz(status,0))
Same error. Not sure what's going on with this one.
 
It might be easier if you could post a sample copy of your db with test data.
I was hoping to avoid that, but I'll try to take out what's not necessary and see if I can get it small enough. What is the max size limit for sending files?
 
you don't need to post any db.
just post a Snapshot of the Table Structure of tblWeekPlans (especially those fields involved in DCount()).
 
There you go.
 

Attachments

  • tblWeeklyPlans.PNG
    tblWeeklyPlans.PNG
    10.4 KB · Views: 412
statusFK is String:

DCount("*", "tblWeeklyPlans", "[UserIDFK] = " & Nz(lngUserID,0) & " AND [StatusFK] <> '" & Nz([status],"@!") & "'")
 
Just FYI, the size limit is 7MB.
I just tried and it fits without any deleting. It's not nearly as big as the first version and it does a lot more. I took all the advise on here and redesigned it. I have another question out there about filtering subreports. I will upload the db on that one. Thanks for everything.
 
I just tried and it fits without any deleting. It's not nearly as big as the first version and it does a lot more. I took all the advise on here and redesigned it. I have another question out there about filtering subreports. I will upload the db on that one. Thanks for everything.
I suggest you zip it up before posting. Cheers!
 
statusFK is String:

DCount("*", "tblWeeklyPlans", "[UserIDFK] = " & Nz(lngUserID,0) & " AND [StatusFK] <> '" & Nz([status],"@!") & "'")
didn't work either. I just realized that "lngUserID is used as a parameter in a function. I should be just glngUserID, I tried it with that and it still didnt' work. Taking a break for tonight. I'll be back at it tomorrow. Thanks!
 

Users who are viewing this thread

Back
Top Bottom