[RESOLVED] Access 2003 Recordset problem
hey everyone. can anyone look at my code and tell me what im doing wrong? im trying to open up a recordset with all rows from a table but when i do, it just has the first row. i know the sql string is correct because when i run it in the querry builder, it has all rows
Code:
Option Compare Database
Private Sub Report_Open(Cancel As Integer)
On Error GoTo errorhandler
Dim SelectStrings As String
Dim MyRecordSets As Recordset
Dim QuestionArrays As Variant
Dim Counters As Integer
SelectStrings = "Select * From tblQuestionResults"
Set MyRecordSets = CurrentDb.OpenRecordset(SelectStrings)
If Not MyRecordSets.EOF Then QuestionArrays = MyRecordSets.GetRows(MyRecordSets.RecordCount)
Counter = MyRecordSets.RecordCount
MsgBox (Counter)
MyRecordSets.Close
errorhandler:
If Err.Number = 0 Then
Else
MsgBox (Err.Description)
End If
End Sub
Re: Access 2003 Recordset problem
What number is displayed in the message box?
Re: Access 2003 Recordset problem
It is recommended that you use Option Explicit to avoid spelling mistakes in variable names.
You declared Counters, but later used Counter
To get correct RecordCount you have to MoveLast first,
but to Get all Rows you have to go back with MoveFirst.
Code:
With MyRecordSets
If Not .EOF Then
.MoveLast
Counter = .RecordCount
.MoveFirst
QuestionArrays = .GetRows(Counter)
End If
.Close
End With
MsgBox Counter
Re: Access 2003 Recordset problem
Re: Access 2003 Recordset problem
Please mark your thread as Resolved by using Thread Tools on the top of the web page.