Import access data to excel based on criteria

0

I have a table in access and I can even pull its data to an excel worksheet (I can do this using the code below), but I would like to be able to pull only some data (based on criteria such as an advanced excel, only realized between excel and access). Note that the table in the access has type 15 columns and my filter would only be about 5 columns.

Code that I already have and that works well (the problem is that it pulls the entire access table):

Sub BuscaDoAccess()

    Dim MDB As New Connection
    Dim RS As New Recordset
    Dim FD As ADODB.Field
    Dim SQL As String

    MDB.Open "Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data 
    Source=C:\Users\Clebson\Desktop\BD.mdb"

    SQL = "select * from HistoricoGeral"
    COL = 2

    RS.Open SQL, MDB

    If Not RS.EOF Then
        For Each FD In RS.Fields
            Sheets("Planilha1").Cells(1, COL).Value = FD.Name
            COL = COL + 1
        Next FD

        COL = 2
        ThisWorkbook.Sheets("Planilha1").Cells(2, COL).CopyFromRecordset RS
    End If

    RS.Close
    MDB.Close

    Set MDB = Nothing
    Set RS = Nothing
    Set FD = Nothing

End Sub
    
asked by anonymous 18.10.2017 / 18:18

0 answers