I'm trying to move through a recordset but I only want it to move through 10 records and then stop (even if the record count is higher)
I tried a for loop but I get mixed results.
a rs.eof works fine but I don't want all the results I only want the 10 of those (or less if there are less)
remember if there are less than 10 records I can't use rs.movenext or I get an error as there aren't more than 10
suggestions?
Code:
Dim rs As dao.Recordset
Dim db As dao.Database
Dim strSQL As String
strSQL = "SELECT tblSchoolMemos.*, tblSchoolMemos.ID " & _
"FROM tblSchoolMemos " & _
"ORDER BY tblSchoolMemos.ID;"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
TextBoxControl = ""
rs.MoveFirst
rs.MoveLast
If rs.RecordCount = 0 Then
TextBoxControl = "No contact history as of yet"
Else
Dim countRec As Long
countRec = rs.RecordCount
Debug.Print String(255, vbNewLine)
Debug.Print countRec
rs.MoveFirst
For i = 0 To IIf(countRec >= 10, 10, countRec)
i = i + 1
TextBoxControl = i & " " & rs!contactmemo & " " & rs!memodate & vbCrLf & TextBoxControl
rs.MoveNext
Next
End If
rs.Close
Set rs = Nothing