Results 1 to 2 of 2

Thread: Index Required When Querying Table Type Recordset

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Index Required When Querying Table Type Recordset

    Hope this helps someone else as took quite a while to troubleshoot.

    --------------------------------

    RE: Microsoft Access
    Table Query where Table includes a PrimaryKey

    Per Microsoft:

    If recordset refers to a table-type Recordset (Microsoft Jet workspaces
    only), movement follows the current index. You can set the current
    index by using the Index property. If you don't set the current index,
    the order of returned records is undefined

    When querying a table type recordset (MS Jet) which includes a PrimaryKey (Index) the following code will eventually fail under certain conditions as Access looses the pointer to the Index.

    VB Code:
    1. With rsSource
    2.    
    3.       .MoveFirst
    4.  
    5.       'Get All Daily Records
    6.       Do Until .EOF
    7.  
    8.            'do something
    9.       Loop
    10.  
    11.    End With

    ------------------------------------------------------

    By referencing the Table Index PRIOR to using the table you are assured
    MS Access knows what Index is being used.
    VB Code:
    1. With rsSource
    2.    
    3.       .Index = "PrimaryKey"        '<<<CRITICAL
    4.       .MoveFirst
    5.  
    6.       'Get All Daily Records
    7.       Do Until .EOF
    8.  
    9.            'do something
    10.       Loop
    11.  
    12.    End With
    Last edited by dw85745; Nov 8th, 2005 at 08:31 AM.

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

    Re: Index Required When Querying Table Type Recordset

    Thanks for the research and tip!

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