+ Reply to Thread
Results 1 to 2 of 2

Using DSUM on a Recordset

  1. #1
    Chaplain Doug
    Guest

    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. #2
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1