PC Review


Reply
Thread Tools Rate Thread

Dsum with variable

 
 
laavista
Guest
Posts: n/a
 
      13th Apr 2009
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!!
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      14th Apr 2009
On Mon, 13 Apr 2009 15:57:04 -0700, laavista
<(E-Mail Removed)> wrote:

>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?
--

John W. Vinson [MVP]
 
Reply With Quote
 
laavista
Guest
Posts: n/a
 
      14th Apr 2009
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" wrote:

> On Mon, 13 Apr 2009 15:57:04 -0700, laavista
> <(E-Mail Removed)> wrote:
>
> >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?
> --
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      14th Apr 2009
On Mon, 13 Apr 2009 17:11:02 -0700, laavista
<(E-Mail Removed)> wrote:

>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?
--

John W. Vinson [MVP]
 
Reply With Quote
 
laavista
Guest
Posts: n/a
 
      14th Apr 2009
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" wrote:

> On Mon, 13 Apr 2009 17:11:02 -0700, laavista
> <(E-Mail Removed)> wrote:
>
> >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?
> --
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DSUM with variable Criteria Michael Dam Microsoft Excel Worksheet Functions 5 18th Dec 2007 06:29 PM
SqlConnection Object in Application Variable OR Session Variable OR open/close pratham Microsoft ASP .NET 3 31st Aug 2006 08:26 PM
VBA with a variable in a query using a dsum funtion =?Utf-8?B?TW9uYS1BQkU=?= Microsoft Access Queries 2 25th Aug 2006 01:32 PM
Dsum - Pass a variable for the column? idta@hotmail.com Microsoft Access 4 21st Nov 2005 05:06 AM
Using DSUM function with variable "Field", etc =?Utf-8?B?Sk1DUw==?= Microsoft Excel Programming 6 23rd Mar 2004 11:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 PM.