Solved

dsum function in Vb?

Posted on 2002-03-07
8
1,363 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 51

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 51

Accepted Solution

by:
Ryan Chong earned 200 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:kcm76
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 51

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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