?
Solved

dsum function in Vb?

Posted on 2002-03-07
8
Medium Priority
?
1,419 Views
Last Modified: 2008-02-01
How can I use the MSAccess aggregated dsum function in a recordset in VB?

When I use it on a recordset, I get a 3085 error
Undefined function 'DSum' in expression.

Example:
SELECT Table1.Id, Table1.Value1, Table1.Value2, DSum("Rest","Query4","N<=" & [Id]) AS Value3 FROM Table1

Please help me.
0
Comment
Question by:seifus
  • 4
  • 3
8 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 6849029
Use:

SELECT Table1.Id, Table1.Value1, Table1.Value2, (SELECT Sum(Rest) FROM Query4 Where N<= Table1.Id) AS Value3 FROM Table1

or

SQL = "SELECT Table1.Id, Table1.Value1, Table1.Value2, (SELECT Sum(Rest) FROM Query4 Where N<=" [Id] ") AS Value3 FROM Table1"

regards
0
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 800 total points
ID: 6849034
SQL = "SELECT Table1.Id, Table1.Value1, Table1.Value2, (SELECT Sum(Rest) FROM Query4 Where N<=" [Id]
") AS Value3 FROM Table1"

should be

SQL = "SELECT Table1.Id, Table1.Value1, Table1.Value2, (SELECT Sum(Rest) FROM Query4 Where N<=" & [Id] &
") AS Value3 FROM Table1"

if [id] is dynamic value.
0
 
LVL 1

Author Comment

by:seifus
ID: 6851183
Thanks ryancys
Did you prove this query?
It asks me the value of Id, because it belongs to Table1 and in vb6 I get this error: 3061, 1 parameters were expected.

Yes, Id is dynamic, but inside the query, it changes in each record.

For this reason it works fine with DSUM, but I can't use it on VB

Is there any Reference to add in Vb to use DSUM?
or any other solution?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Chandramouli k
ID: 6851450
Instead of creating the query in msaccess try to create it in Vb using QueryDef object dynamically.

regards
KCM
0
 
LVL 1

Author Comment

by:seifus
ID: 6852902
Id changes on each record not in every Query
0
 
LVL 1

Author Comment

by:seifus
ID: 6852984
Forgive me ryancys, I had made a mistake

The correct answer is: SELECT Table1.Id, Table1.Value1, Table1.Value2, (SELECT Sum(Rest) FROM Query4 Where N<=[Id]) AS Value3 FROM Table1

The Problem was, that I used & with [Id]

Thanks a lot, you save me.


0
 
LVL 1

Author Comment

by:seifus
ID: 6853002
The answer solved my problem
But, why can't I use DSUM in VB?
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 6855236
Hi, I think you cannot use it bcos maybe your Database Engine is Not Recognize it which the DSum function only avaialbe in M$ Access.

Cheers,
ryancys
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question