Dsum with variable

L

laavista

I need to sum a field.
Table name: t_creditsused
Field to sum: CreditsUsed
IF field creditsID = the variable named longintCredits_CreditsID

The following syntax is not working...

intCreditsUsed = Nz(DSum("[CreditsUsed]", "t_creditsused", "[creditsID] = "
& longintCredits_CreditsID))

I've read all the threads on dsum with no luck.
Your help would be greatly appreciated!!
 
J

John W. Vinson

I need to sum a field.
Table name: t_creditsused
Field to sum: CreditsUsed
IF field creditsID = the variable named longintCredits_CreditsID

The following syntax is not working...

intCreditsUsed = Nz(DSum("[CreditsUsed]", "t_creditsused", "[creditsID] = "
& longintCredits_CreditsID))

I've read all the threads on dsum with no luck.
Your help would be greatly appreciated!!

What's "not working"? Symptoms? What's the datatype of CreditsID? What's the
actual value of longintCredits_CreditsID? If you open t_creditsused and use
the binoculars search icon, do you find that record?
 
L

laavista

I should have included this info in my question.

I'm getting the error "syntax error (missing operator) in query expression
'[creditsid]=",

Field "CreditsUsed": integer
"CreditsID" is an autonumbered field (long integer)

The value of longintCredits_CreditsID = 2 and I can "find" the record

Thanks for looking at this.


John W. Vinson said:
I need to sum a field.
Table name: t_creditsused
Field to sum: CreditsUsed
IF field creditsID = the variable named longintCredits_CreditsID

The following syntax is not working...

intCreditsUsed = Nz(DSum("[CreditsUsed]", "t_creditsused", "[creditsID] = "
& longintCredits_CreditsID))

I've read all the threads on dsum with no luck.
Your help would be greatly appreciated!!

What's "not working"? Symptoms? What's the datatype of CreditsID? What's the
actual value of longintCredits_CreditsID? If you open t_creditsused and use
the binoculars search icon, do you find that record?
 
J

John W. Vinson

I should have included this info in my question.

I'm getting the error "syntax error (missing operator) in query expression
'[creditsid]=",

Field "CreditsUsed": integer
"CreditsID" is an autonumbered field (long integer)

The value of longintCredits_CreditsID = 2 and I can "find" the record

Thanks for looking at this.

That suggests that the variable isn't defined. Try doing some debugging:

Dim strCrit As String
strCrit = "[creditsID] = " & longintCredits_CreditsID
intCreditsUsed = Nz(DSum("[CreditsUsed]", "t_creditsused", strCrit))

Put a breakpoint on the intCreditsUsed = line, run the code, and see if
strCrit is in fact being set correctly. At what point is
longintCredits_CreditID being set, and for that matter dimensioned?
 
L

laavista

John, you are a genius! I put in your code, and it summed correctly for the
creditID! I knew I had a syntax error in my dsum statement, but couldn't
figure out what it was. Your breaking it down using strCrit as the variable
worked.
THANK YOU so much. I REALLY appreciate your time in helping me with this.

John W. Vinson said:
I should have included this info in my question.

I'm getting the error "syntax error (missing operator) in query expression
'[creditsid]=",

Field "CreditsUsed": integer
"CreditsID" is an autonumbered field (long integer)

The value of longintCredits_CreditsID = 2 and I can "find" the record

Thanks for looking at this.

That suggests that the variable isn't defined. Try doing some debugging:

Dim strCrit As String
strCrit = "[creditsID] = " & longintCredits_CreditsID
intCreditsUsed = Nz(DSum("[CreditsUsed]", "t_creditsused", strCrit))

Put a breakpoint on the intCreditsUsed = line, run the code, and see if
strCrit is in fact being set correctly. At what point is
longintCredits_CreditID being set, and for that matter dimensioned?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top