Using a query field within a dsum expression (1 Viewer)

Drand

Registered User.
Local time
Today, 16:59
Joined
Jun 8, 2019
Messages
179
This may not be logical, but can you use a field from within a query as criteria in a dsum expression in the same query?

This is the expression I currently use:

This Week: DSum("Quantity","QryStockOutGroup","[MyWeek] = Forms!FrmStockOutGroup!MyWeek And [MyYear] = Forms!FrmStockOutGroup!MyYear And [Grp] = 'Coffee'")

What I am trying to do is substitute "[Grp] = 'Coffee'" with "Grp = the field within the query where coffee is one of them"

Hope this makes sense!

Thanks

.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:59
Joined
Oct 29, 2018
Messages
21,358
Hi. Yes, I think that's possible. What happened when you tried it? Did you concatenate it in? For example:
Code:
DSum("Quantity",...,"...[Grp]='" & [FieldName] & "'")
 

Ranman256

Well-known member
Local time
Today, 01:59
Joined
Apr 9, 2015
Messages
4,339
the variables must be outside the quotations:

DSum("Quantity","QryStockOutGroup","[MyWeek] =" & Forms!FrmStockOutGroup!MyWeek & " And [MyYear] = " & Forms!FrmStockOutGroup!MyYear & " And [Grp] ='Coffee'")
 

Drand

Registered User.
Local time
Today, 16:59
Joined
Jun 8, 2019
Messages
179
[Grp]='" & [FieldName] & "'"
Hi. Yes, I think that's possible. What happened when you tried it? Did you concatenate it in? For example:
Code:
DSum("Quantity",...,"...[Grp]='" & [FieldName] & "'")
I hadn't tried it yet as I did not know the syntax.
I tried your suggestion and it worked perfectly. Thank you for your help, much appreciated
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:59
Joined
Oct 29, 2018
Messages
21,358
I hadn't tried it yet as I did not know the syntax.
I tried your suggestion and it worked perfectly. Thank you for your help, much appreciated
Hi. You're welcome. Glad to hear you got it work. Ranman and I were happy to assist. Good luck with your project.
 

Users who are viewing this thread

Top Bottom