Howdy,
I'm trying to set the value of an unbound field on an unbound form to a count of values returned in a query. A buddy of mine gave me the following code to use:
In the immediate window, I'm getting a RecordCount of 0, when there are 28 records returned in the query. I've read some other posts that mention the use of rs.MoveFirst, but I'm not very familiar with VBA, and any good advice would be most appreciated.
Thanks in advance,
Mike
I'm trying to set the value of an unbound field on an unbound form to a count of values returned in a query. A buddy of mine gave me the following code to use:
Code:
Function RecordCount(ByVal queryname As String) As Long
Dim db As Database
Dim rs As Recordset
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset(queryname)
rs.MoveLast
rs.Close
Set rs = Nothing
Set db = Nothing
[COLOR=green]'this returns the counter[/color]
RecordCount = rs.RecordCount
End Function
In the immediate window, I'm getting a RecordCount of 0, when there are 28 records returned in the query. I've read some other posts that mention the use of rs.MoveFirst, but I'm not very familiar with VBA, and any good advice would be most appreciated.
Thanks in advance,
Mike