By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Variable (Function) as Criteria still not working...

P: 7
I'm trying to use a variable (as string) within criteria for DCount. I searched and found that you can't, and that instead I would need to write a one line function to return that same value.

1) Is this true?

2) Regardless, what would the final line look like? I would imagine something like this?:

Calculate = DCount("[expr]", "domain", "[expr] = GetValue()")
???

Clearly this doesn't work:
Calculate = DCount("[expr]", "domain", "[expr] = stringVariable")

Thanks in advance for your help! Oh and I sincerely encourage multiple responses to the same noob question. Thank you so much.
Oct 17 '06 #1
Share this Question
Share on Google+
4 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
This will work:

Calculate = DCount("[expr]", "domain", "[expr]=" & stringVariable)



I'm trying to use a variable (as string) within criteria for DCount. I searched and found that you can't, and that instead I would need to write a one line function to return that same value.

1) Is this true?

2) Regardless, what would the final line look like? I would imagine something like this?:

Calculate = DCount("[expr]", "domain", "[expr] = GetValue()")
???

Clearly this doesn't work:
Calculate = DCount("[expr]", "domain", "[expr] = stringVariable")

Thanks in advance for your help! Oh and I sincerely encourage multiple responses to the same noob question. Thank you so much.
Oct 17 '06 #2

P: 7
i've tried that too...

It doesn't work. I don't understand that line either. arg!

ok something more helpful:

Private Function Calculate(ethnic As String, status As String) As Integer
Calculate = DCount("[ethnicity]", status, "[Ethnicity] =" & ethnic)

is what I have. i MsgBox out both ethnic and status to find that both are read correctly. Why won't this work!?

please and thank you
Oct 17 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Sorry I forgot it was a string, it needs single quotes.

Calculate = DCount("[ethnicity]", status, "[Ethnicity] ='" & ethnic) & "'"



i've tried that too...

It doesn't work. I don't understand that line either. arg!

ok something more helpful:

Private Function Calculate(ethnic As String, status As String) As Integer
Calculate = DCount("[ethnicity]", status, "[Ethnicity] =" & ethnic)

is what I have. i MsgBox out both ethnic and status to find that both are read correctly. Why won't this work!?

please and thank you
Oct 17 '06 #4

P: 7
For clarification should anyone in the future find this, he's absolutely right and genius, but even the best of us have some typos.

Calculate = DCount("[ethnicity]", status, "[ethnicity] ='" & ethnic & "'")

worked perfectly.

Thank you so much!
Oct 17 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.