Results 1 to 5 of 5

Thread: [RESOLVED] Access 2003 Recordset problem

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved [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
    Last edited by Hack; Jun 23rd, 2008 at 11:29 AM. Reason: Added Code Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Access 2003 Recordset problem

    What number is displayed in the message box?

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Re: Access 2003 Recordset problem

    ooohhh. cool thanks

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Access 2003 Recordset problem

    Please mark your thread as Resolved by using Thread Tools on the top of the web page.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width