Hi,
Is it possible for a excel macro to query an Access database with more than one criteria and download it to excel?
I've done it so it downloads based on one criteria, but I want to to download based on Person as well as date, so for example it will return the work for John Smith on the 10th December 2013.
This is the query code I have which works fine for one criteria
This is all of the code I've got so far
Thanks,
Is it possible for a excel macro to query an Access database with more than one criteria and download it to excel?
I've done it so it downloads based on one criteria, but I want to to download based on Person as well as date, so for example it will return the work for John Smith on the 10th December 2013.
This is the query code I have which works fine for one criteria
Code:
sSQL = "SELECT * FROM workflowdata WHERE Date ='" & ShDest.Range("K1").Value & "'"
This is all of the code I've got so far
Code:
Sub ReturnWork()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim MyConn
Dim i As Long
Dim ShDest As Worksheet
Dim sSQL As String
Set ShDest = Sheets("Workflow")
sSQL = "SELECT * FROM workflowdata WHERE Date ='" & ShDest.Range("K1").Value & "'"
Set cnn = New ADODB.Connection
MyConn = ThisWorkbook.Path & Application.PathSeparator & TARGET_DB
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = "test"
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open Source:=sSQL, ActiveConnection:=cnn, _
CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic, _
Options:=adCmdText
'clear existing data on the sheet
ShDest.Activate
Range("A1").CurrentRegion.Clear
'create field headers
i = 0
With Range("A1")
For Each fld In rst.Fields
.Offset(0, i).Value = fld.Name
i = i + 1
Next fld
End With
'transfer data to Excel
Range("A2").CopyFromRecordset rst
' Close the connection
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
Thanks,