I have an Excel
sheet with data where a column is blank for first several rows (8 rows exactly). As the provider scans first 8 rows only, the query of ADODB
Recordset
returns 0 in this case. But if I fill the data within first 8 rows, then the ADODB
Recordset
returns results and I can get the record count of the query result correctly.
I tried changing IMEX to 0,1,2 and 3 and even tried changing CursorLocation and CursorType in the below query. So I would like to know if we can skip the blank rows and start the query from non-blank row.
Sub GetRecordCount()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset, StrSQL As String
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ActiveWorkbook.FullName & ";" & _
"Extended Properties=""Excel 12.0;HDR=Yes;IMEX=0;Readonly=True"""
End With
cn.Open
Dim k As Variant
StrSQL = "select [BOOKNAME] From [BOOK DETAILS$A4:BN119] Where ([COUPONNUMBER]='ZFX' or [COUPONNUMBER]='ZDL')"
rs.Open StrSQL, cn
k = CInt(Trim(rs.RecordCount))
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub