Hi,
I'm attempting a query using VBA in Excel. Stepping through, I get the error as in the thread subject at '.Open SQL'
I've checked and double checked I have correct spelling and case, etc but I cannot see where the problem is!
I'd be very grateful if anyone could help me identify the problem with the code below.
-Using Excel & Access 2002
I'm attempting a query using VBA in Excel. Stepping through, I get the error as in the thread subject at '.Open SQL'
I've checked and double checked I have correct spelling and case, etc but I cannot see where the problem is!
I'd be very grateful if anyone could help me identify the problem with the code below.
-Using Excel & Access 2002
Code:
Dim xName As String
Dim xStart As Date
Dim xEnd As Date
xName = Chr(34) & Worksheets("Calcs").Range("c5").Value & Chr(34)
xStart = Format(Worksheets("Calcs").Range("c2").Value, "mm/dd/yyyy")
xEnd = Format(Worksheets("Calcs").Range("c3").Value, "mm/dd/yyyy")
sql1 = "SELECT qryTotalDuration.CSTRName, qryTotalDuration.Team, qryTotalDuration.Dept, qryTotalDuration.stepstopdate, qryTotalDuration.ProcessStepName, qryTotalDuration.duration "
sql2 = "FROM qryTotalDuration "
'Dept SQL3
If Worksheets("Calcs").Range("g19").Value = "Y" Then
sql3 = _
"WHERE (((qryTotalDuration.Dept)=" & _
xName & _
") AND ((qryTotalDuration.stepstopdate) " & _
"Between #" & xStart & "# And #" & xEnd & "#)) "
End If
'Team SQL3
If Worksheets("Calcs").Range("g20").Value = "Y" Then
sql3 = _
"WHERE (((qryTotalDuration.Team)=" & _
xName & _
") AND ((qryTotalDuration.stepstopdate) " & _
"Between #" & xStart & "# And #" & xEnd & "#)) "
End If
'CSR SQL3
If Worksheets("Calcs").Range("g21").Value = "Y" Then
sql3 = _
"WHERE (((qryTotalDuration.CSTRName)=" & _
xName & _
") AND ((qryTotalDuration.stepstopdate) " & _
"Between #" & xStart & "# And #" & xEnd & "#)) "
End If
sql4 = ";"
sql = sql1 & sql2 & sql3 & sql4
With rsPubs
.ActiveConnection = vConnection
.Open sql
Worksheets("ActualTime").Range("a2:g65536").Clear
Worksheets("ActualTime").Range("a2").CopyFromRecordset rsPubs
.Close
Comment