C
Chaplain Doug
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'")
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'")