Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Using DSUM on a Recordset

Excel 2003. I have the following code that queries an SQL database and fills
up a recordset called "rs." Is there a way to then use the DSUM function on
the recordset? I get an error when I try using the DSUM. The connection
works fine and the recordset is filled without error.

Set cn = New ADODB.Connection
cn.Open "Provider=sqloledb;" & _
"Data Source=HQServer;" & _
"Initial Catalog=Good_News_FE;" & _
"User ID=FEOpen7;" & _
"Password=fe"
sql = "SELECT GL7PROJECTS.PROJECTID AS ProjectID, GL7PROJECTS.DESCRIPTION
AS [Project Description], GL7ACCOUNTS.ACCOUNTNUMBER AS Account,
GL7ACCOUNTS.DESCRIPTION AS [Account Description], GL7FISCALPERIODS.SEQUENCE
AS [Month], GL7PROJECTBUDGETDETAILS.AMOUNT AS [Month Amt],
GL7PROJECTBUDGETS.AMOUNT AS Total, GL7FISCALPERIODS.STARTDATE,
GL7FISCALPERIODS.ENDDATE " & _
"FROM ((((GL7PROJECTBUDGETS INNER JOIN GL7PROJECTBUDGETDETAILS ON
GL7PROJECTBUDGETS.GL7PROJECTBUDGETSID =
GL7PROJECTBUDGETDETAILS.GL7PROJECTBUDGETSID) INNER JOIN GL7ACCOUNTS ON
GL7PROJECTBUDGETS.GL7ACCOUNTSID = GL7ACCOUNTS.GL7ACCOUNTSID) INNER JOIN
GL7FISCALPERIODS ON (GL7PROJECTBUDGETDETAILS.GL7FISCALPERIODSID =
GL7FISCALPERIODS.GL7FISCALPERIODSID) AND
(GL7PROJECTBUDGETDETAILS.GL7FISCALPERIODSID =
GL7FISCALPERIODS.GL7FISCALPERIODSID)) INNER JOIN GL7PROJECTS ON
GL7PROJECTBUDGETS.GL7PROJECTSID = GL7PROJECTS.GL7PROJECTSID) " & _
"INNER JOIN GL7FISCALYEARS ON GL7FISCALPERIODS.GL7FISCALYEARSID =
GL7FISCALYEARS.GL7FISCALYEARSID " & _
"WHERE (((GL7FISCALPERIODS.STARTDATE)='1/1/2006') AND
((GL7FISCALPERIODS.ENDDATE)<='12/31/2006')) " & _
"ORDER BY GL7PROJECTS.PROJECTID, GL7ACCOUNTS.ACCOUNTNUMBER,
GL7FISCALPERIODS.SEQUENCE;"

Set rs = cn.Execute(sql, , adCmdText)

*THIS IS WHAT DOES NOT WORK

IFL = DSum("[Month Amt]", rs, "[Account]='1-4100'")

--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using DSUM on a Recordset

There are several thinks wrong with your attempt to use DSUM in VBA, but the
biggest constraint is that it only works on data in a range:

From help on DSUM:

DSUM(database,field,criteria)

Database is the range of cells that make up the list or database. A
database is a list of related data in which rows of related information are
records and columns of data are fields. The first row of the list contains
labels for each column.

Field indicates which column is used in the function. Field can be given
as text with the column label enclosed between double quotation marks, such
as "Age" or "Yield," or as a number that represents the position of the
column within the list: 1 for the first column, 2 for the second column, and
so on.

Criteria is the range of cells that contains the conditions you specify.
You can use any range for the criteria argument, as long as it includes at
least one column label and at least one cell below the column label for
specifying a condition for the column.

===========

If you are using SQL, you shouldn't need to use DSUM. Adjust your query to
return the summary information you seek.

--
Regards,
Tom Ogilvy


"Chaplain Doug" wrote in message
...
Excel 2003. I have the following code that queries an SQL database and

fills
up a recordset called "rs." Is there a way to then use the DSUM function

on
the recordset? I get an error when I try using the DSUM. The connection
works fine and the recordset is filled without error.

Set cn = New ADODB.Connection
cn.Open "Provider=sqloledb;" & _
"Data Source=HQServer;" & _
"Initial Catalog=Good_News_FE;" & _
"User ID=FEOpen7;" & _
"Password=fe"
sql = "SELECT GL7PROJECTS.PROJECTID AS ProjectID,

GL7PROJECTS.DESCRIPTION
AS [Project Description], GL7ACCOUNTS.ACCOUNTNUMBER AS Account,
GL7ACCOUNTS.DESCRIPTION AS [Account Description],

GL7FISCALPERIODS.SEQUENCE
AS [Month], GL7PROJECTBUDGETDETAILS.AMOUNT AS [Month Amt],
GL7PROJECTBUDGETS.AMOUNT AS Total, GL7FISCALPERIODS.STARTDATE,
GL7FISCALPERIODS.ENDDATE " & _
"FROM ((((GL7PROJECTBUDGETS INNER JOIN GL7PROJECTBUDGETDETAILS ON
GL7PROJECTBUDGETS.GL7PROJECTBUDGETSID =
GL7PROJECTBUDGETDETAILS.GL7PROJECTBUDGETSID) INNER JOIN GL7ACCOUNTS ON
GL7PROJECTBUDGETS.GL7ACCOUNTSID = GL7ACCOUNTS.GL7ACCOUNTSID) INNER JOIN
GL7FISCALPERIODS ON (GL7PROJECTBUDGETDETAILS.GL7FISCALPERIODSID =
GL7FISCALPERIODS.GL7FISCALPERIODSID) AND
(GL7PROJECTBUDGETDETAILS.GL7FISCALPERIODSID =
GL7FISCALPERIODS.GL7FISCALPERIODSID)) INNER JOIN GL7PROJECTS ON
GL7PROJECTBUDGETS.GL7PROJECTSID = GL7PROJECTS.GL7PROJECTSID) " & _
"INNER JOIN GL7FISCALYEARS ON GL7FISCALPERIODS.GL7FISCALYEARSID =
GL7FISCALYEARS.GL7FISCALYEARSID " & _
"WHERE (((GL7FISCALPERIODS.STARTDATE)='1/1/2006') AND
((GL7FISCALPERIODS.ENDDATE)<='12/31/2006')) " & _
"ORDER BY GL7PROJECTS.PROJECTID, GL7ACCOUNTS.ACCOUNTNUMBER,
GL7FISCALPERIODS.SEQUENCE;"

Set rs = cn.Execute(sql, , adCmdText)

*THIS IS WHAT DOES NOT WORK

IFL = DSum("[Month Amt]", rs, "[Account]='1-4100'")

--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy From Recordset Nath Excel Programming 0 July 13th 04 12:30 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM
Looping Through A Recordset Tim Williams Excel Programming 0 August 20th 03 05:52 AM
Looping Through A Recordset Bob Phillips[_5_] Excel Programming 0 August 19th 03 03:34 PM


All times are GMT +1. The time now is 12:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"