Re: How to get recordcount or number of records when using linked tables
- From: salad <oil@xxxxxxxxxxx>
- Date: Thu, 18 May 2006 07:20:11 GMT
Robert wrote:
How do you get an accurate count of the number of records returned from
a query when using linked tables.
I have an access 2003 database as a front end to another access 2003
database that contains only tables. I have linked the tables for the
front end to the back end database.
I am trying to set the recordsource of a form to a query established by
the user to narrow the scope but I don't want to display the form if
there are no records that match the query. So,
given
Dim db As Database
Dim rst As Recordset
Dim sql As String
Dim MyRecordSource As String
Dim RecordCountVariable As Integer
Set db = CurrentDb()
Set rst = db.OpenRecordset(sqlF98, dbOpenDynaset, dbReadOnly)
If Not (rst.BOF Or rst.EOF) Then
rst.MoveLast
RecordCountVariable = rst.RecordCount
rst.MoveFirst '(If you are going to do something else
here)
Else
RecordCountVariable = 0
End If
If RecordCountVariable = 0 Then
MsgBox ("No records match search criteria")
Else
Me.RecordSource = sqlF98
End If
Set db = CurrentDb()
Set rst = db.OpenRecordset(sqlF98, dbOpenDynaset, dbReadOnly)
If rst.RecordCount > 0 then rst.MoveLast
msgbox rst.recordcount
rst.close
set rst = Nothing
.
rst.recordcount always returns zero (0) but I know there are records
because when I set me.recordsource = sqlF98 the filter is set correctly
and I only get a subset of the data.
Help on .recordcount indicates it doesn't work on linked tables. What
property do you use then to get # of records returned in a query?
Thanks in Advance
Robert
- References:
- Prev by Date: Re: Preventing duplicate records in query/database design?
- Next by Date: Re: NotInList adding new entry as a new record each time
- Previous by thread: Re: How to get recordcount or number of records when using linked tables
- Next by thread: Changin fields' names
- Index(es):
Relevant Pages
|