Record Count always 100?

kirkm

Registered User.
Local time
Tomorrow, 01:41
Joined
Oct 30, 2008
Messages
1,257
Code:
Function MyBBList() As DAO.Database
    Set MyBBList = DAO.OpenDatabase("\\Win10-pc\Desktop\TestBBTableMay2020 (1222a).mdb", False, False)
End Function
Code:
Function GetBBPrefixAndLC(y, Title) As DAO.Recordset
    Dim sql As String
             'Construct sql

    With MyBBList.CreateQueryDef("", sql)
        If .OpenRecordset.RecordCount > 0 Then
        .OpenRecordset.MoveLast
        .OpenRecordset.MoveFirst
        End If
        Set GetBBPrefixAndLC = .OpenRecordset
        .Close
    End With
End Function
Normally I find MoveLast will give the correct Record Count (if it's more than 0)
But in this case it's not. It's always 100. Can I get the 'correct' count somehow?
 
Wouldn't that depend on whatever sql is?
 
how about:
Code:
Function GetBBPrefixAndLC(y, Title) As DAO.Recordset
    Dim sql As String
             'Construct sql
    Dim rs As DAO.Recordset
    Set rs = MyBBList.CreateQueryDef("", sql).OpenRecordset
    With rs
        If Not (.BOF And EOF) Then
            .MoveLast
            .MoveFirst
        End If
        Set GetBBPrefixAndLC = rs
        .Close
    End With
End Function
 
Thanks arne, that lets me get the correct record count; any idea why my routine returns either 0 or 100 ? Just curious...
 
Struck a problem with Set GetBBPrefixAndLC = rs
The function doesn't return the recordset (as it does with Set GetBBPrefixAndLC = .OpenRecordset)
And causes error 3420 Object Invalid or no longer set
Any thoughts on that ?
 
don't close rs
Code:
Function GetBBPrefixAndLC(y, Title) As DAO.Recordset
    Dim sql As String
             'Construct sql
    Dim rs As DAO.Recordset
    Set rs = MyBBList.CreateQueryDef("", sql).OpenRecordset
    With rs
        If Not (.BOF And EOF) Then
            .MoveLast
            .MoveFirst
        End If
        Set GetBBPrefixAndLC = rs
    End With
End Function
 
Well that was pretty easy! Kindof weird tho as hasn't it been assigned to another in the previous line?
 

Users who are viewing this thread

Back
Top Bottom