ADO/SQL to extract SUM Query

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I happened upon the following code for using ADO/SQL to extract a record count for Access Queries...

Code:
Private Function Record_Count(sSQL As String)
    Set cnn = New ADODB.Connection
    With cnn
            .CommandTimeout = 0
            .Provider = "Microsoft.Jet.OLEDB.4.0"
            .ConnectionString = "Data Source=" & FolderName & TARGET_DB
            .Open
    End With
     
    Set cmd = New ADODB.Command
        With cmd
            .CommandTimeout = 0
            .CommandType = adCmdText
            .CommandText = sSQL
            .ActiveConnection = cnn
        End With
     
    Set rst = New ADODB.Recordset
        rst.Open cmd, , adOpenStatic, adLockReadOnly
        Record_Count = rst.RecordCount
     
    rst.Close
    cnn.Close
    Set cnn = Nothing
    Set cmd = Nothing
    Set rst = Nothing
End Function
Is it possible to revise this to extract the SUM of a field in a query? Or do I need to go another route?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In other words, I have my query in SQL (via ADO) that I could extract all the records into excel, sum the field(s) that I need, and then delete that information from Excel.

Is it possible to shortcut that and just return the sum(s) I am looking for?
 
Upvote 0

Forum statistics

Threads
1,215,776
Messages
6,126,830
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top