Need a space after Min(importdate) so the text doesn't run together when compiled. Use: Debug.Print StrSQL5 to see the compiled SQL statement in Immediate Window.
Why are you using LEFT and FORMAT on the date criteria? Date value is actually in a text field? However, I tested this and should work.
Is SpecialFlag a Yes/No field? Yes/No field can never be Null, it's either True or False. No records will match this.
I tested this query/subquery syntax in VBA and it does return a single record with count value. Micron, might look at the query again. CountRecs is field name.
Now, as Micron noted, need to instantiate Excel objects. One example:
Code:
Dim xlx As Excel.Application, xlw As Excel.Workbook, xls As Excel.Worksheet
Dim blnEXCEL As Boolean
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlx = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
'xlx.Visible = True
Set xlw = xlx.Workbooks.Open("your path here", , True) ' opens in read-only mode
Set xls = xlw.Worksheets("your worksheet here")
'recordset code here
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
If blnEXCEL = True Then xlx.Quit
Set xlx = Nothing