Results 1 to 3 of 3

Thread: Trouble opening a recordset in Access 2007 form code

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602

    Trouble opening a recordset in Access 2007 form code

    I'm using some very basic code copied from a project I did a couple of years ago.
    In a Sub in the code page for a form in Access 2007, I'm using this code

    Dim RS as Recordset
    Set RS = CurrentDB.OpenRecordset("Select * from Table1")

    It doesn't matter what I query, I get RS.Recordcount = 1, which I assume means it isn't getting the actual results

    As I mentioned, I used this same code in another db before with no problem.
    Also, in this same project, I've had no trouble using queries to populate objects.

    It's the code above, just returning a recordset, that's causing the problem. And it isn't giving me any kind of error back. That's making it impossible for me to solve.

    Any help would be appreciated.

    Thanks.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Trouble opening a recordset in Access 2007 form code

    You have to MoveLast before reading the Recordcount so it will return the true number.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Trouble opening a recordset in Access 2007 form code

    do not rely on the recordcount property in ADO as it depends on cursortype and whether the recordset is dynamic, static or forward only

    probably used to work ok in DAO
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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