I need to open a recordset, filter it and work on the filtered version.
Method 1 : Unsuccessful (Before and after setting the filter result is the same)
Method 2 : Successful (before and after filtering result is different)
I'm trying to understand why filtering in first method doesn't return the expected record count.
Thanks for any insight.
Method 1 : Unsuccessful (Before and after setting the filter result is the same)
SQL:
Dim XL As String
Dim rs1 As DAO.Recordset
Dim sql As String
XL = CurrentProject.Path & "\book1.xlsx"
If XL = "" Then Exit Sub
sql = " SELECT [Field1] AS OrderNo, "
sql = sql & "[Field2] AS DrawingNo, "
sql = sql & "[Field3] AS ManufacturingNumber "
sql = sql & " FROM [Excel 12.0 Xml;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=" & XL & "].[sheet1$];"
Set rs1 = CurrentDb.OpenRecordset(sql)
rs1.MoveLast
Debug.Print rs1.RecordCount ' Debug = 29'
rs1.MoveFirst
rs1.Filter = "[DrawingNo] LIKE '*C*'"
rs1.MoveLast
Debug.Print rs1.RecordCount ' Debug = 29'
rs1.Close
Method 2 : Successful (before and after filtering result is different)
SQL:
Dim XL As String
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim sql As String
XL = CurrentProject.Path & "\book1.xlsx"
sql = " SELECT [Field1] AS OrderNo, "
sql = sql & "[Field2] AS DrawingNo, "
sql = sql & "[Field3] AS ManufacturingNumber "
sql = sql & " FROM [Excel 12.0 Xml;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=" & XL & "].[sheet1$];"
Set rs1 = CurrentDb.OpenRecordset(sql)
rs1.MoveLast
Debug.Print rs1.RecordCount ' Debug = 29'
rs1.Filter = "[DrawingNo] LIKE '*C*'"
Set rs2 = rs1.OpenRecordset
rs2.MoveLast
Debug.Print rs2.RecordCount ' Debug = 13'
rs1.Close
rs2.Close
I'm trying to understand why filtering in first method doesn't return the expected record count.
Thanks for any insight.