Results 1 to 3 of 3

Problem with Aggregate Function ADO SQL

Threaded View

  1. #1
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Problem with Aggregate Function ADO SQL

    Hi,

    I have a spreadsheet that I populate from an Access database which I have no problem doing, except for the below query.

    The SQL query works fine in Access, but returns no records when running the below code from Excel and there are no error messages. This is the first Aggregate function that I have run from Excel so it's quite possible I'm missing something, but any help would be very much appreciated!

    Option Explicit
    
    Public Sub ImportSD()
    
    
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sql As String
    Dim filenm As String
    Dim scrh As String
    Dim x As Double, y As Double
    Dim usernm As String, pword As String
    Dim lSQL As String
    
    filenm = "\\Sheffield-1\data\bus\339-BusContactCentreSales\Private\WIP Reports\Payplan.mdb"
    
    Set conn = New ADODB.Connection
    conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & filenm & ";", _
                  usernm, pword
                  
    lSQL = "SELECT dateadd('m', datediff('m', 0,[entry Date]),0) As [Set_Month]," & _
           " SUM([Points]) AS [Run_Rate] " & _
           "FROM Combined WHERE [Product Name] LIKE '*BROADBAND*' " & _
           "GROUP BY dateadd('m', datediff('m', 0,[entry Date]),0);"
           
    
    Set rs = New ADODB.Recordset
    rs.Open lSQL, conn, adOpenStatic
    
    Sheets("teams").Range("A38").CopyFromRecordset rs
    
    
    rs.close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing
    
    End Sub
    Last edited by Kyle123; 03-10-2010 at 07:49 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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