Question : Access VBA: Getting Record Count

I'm passing in the table name and the search value.  I keep getting a return count of 1.  It should be 39.  If I delete everything in the table I get 0.

Why is this returning a value of 1 when there are clearly more?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Public Function getRowsVar(tbl As String, searchValue As String) As Integer
 
Dim db As Database
Set db = CurrentDb()
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("SELECT * FROM " + tbl + " WHERE TYPE = '" + searchValue + "';")
r = rs.RecordCount
MsgBox r
MsgBox rs.RecordCount
 
Set rs = Nothing
Set db = Nothing
getRowsVar = r
End Function

Answer : Access VBA: Getting Record Count

Another way to do this is to use DCount:

YourRecordCount = DCount("*", tbl, "type = '" & SearchValue & "'")
Random Solutions  
 
programming4us programming4us