Dim dbConnection As ADODB.Connection
Set dbConnection = New ADODB.Connection
Dim connStr As String
connStr = "myWonderfulConnectionString"
dbConnection.ConnectionString = connStr
dbConnection.Open
Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
Dim sql As String
Dim fromDate As Range
Set fromDate = ActiveSheet.Range("B1")
Dim toDate As Range
Set toDate = ActiveSheet.Range("D1"
sql = "SELECT [WO_NUM]" & _
",[CLSDBY]" & _
",[CLSDDATE]" & _
"FROM [TRACKIT8_from7].[dbo].[TASKS] " & _
"WHERE (CLSDDATE BETWEEN #" & Format(fromDate, "mm/dd/yyyy") & "# AND #" & Format(toDate, "mm/dd/yyyy") & "#)" & _
"OR CLSDDATE IS NULL"
With rsData
.ActiveConnection = dbConnection
.Open sql
If Not rsData.EOF Then
Worksheets("TrackIt").Range("A3").CopyFromRecordset rsData
'ActiveSheet.Range("C6").CopyFromRecordset rsData
End If
End With
|