DLookup in VBA code

Lkwdmntr

Registered User.
Local time
Today, 05:15
Joined
Jul 10, 2019
Messages
319
Hi Guys,

I am working on a point system and made several queries to count items for the points. I tried this VBA code and am getting a syntax error. DLookup is a little different in the code than in access itself. Can anyone help me get this right. CountMonSTC = 21, CountMonStMeals = 9, CountAllBA = 12 which should make Me.MonPotAcntPts = 33 (9 + (21 - 9) + 12)

Me.MonPotAcntPts = (DLookup("Monday", "CountMonMeals") + ((DLookup("Monday", "CountMonSTC") - (DLookup("Monday", "CountMonMeals")) + DLookup("Monday", "CountAllBAMon")​
 
Your parentheses look out of whack. Take out any not directly required for a DLookup(). They aren't necessary with only addition and subtraction.
 
Thanks, that did it.
 
Something not mentioned so far...
You have two identical DLookups for CountMonMeals with + & - which cancel each other out.
Omit both!

Code:
Me.MonPotAcntPts = Nz(DLookup("Monday", "CountMonSTC"),0) + Nz(DLookup("Monday", "CountAllBAMon"),0)
 

Users who are viewing this thread

Back
Top Bottom