Results 1 to 8 of 8

Thread: [RESOLVED] Getting the Recordcount

  1. #1

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    [RESOLVED] Getting the Recordcount

    Hey guys a lil help pls...

    VB Code:
    1. Dim objDB As ADODB.Connection
    2. Dim rs As ADODB.Recordset
    3.  
    4. Private Sub Command1_Click()
    5.    rs.Open "select * from card_Header", objDB.ConnectionString, , , adCmdText
    6.    Debug.Print rs.RecordCount
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.   Set objDB = New ADODB.Connection
    11.   Set rs = New ADODB.Recordset
    12.   objDB.Open "provider=microsoft.jet.oledb.4.0;data source=D:\Documents and Settings\Ruikeish\My Documents\mrserver.mdb"
    13.  
    14. End Sub

    Why does Debug.print rs.RecordCount prints -1? instead of printing the no. of records of the table.

    Thanks a lot...
    Last edited by charmedcharmer; Nov 15th, 2004 at 02:01 AM.
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I knew that I've seen this before.

    The RecordCount property will always be -1 when using a Server Side cursor. Change the CursorLocation property to adUseClient.
    I just searched for rs.recordcount...

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Not exactly true. To get a recordcount you also need to specify a
    cursor type that supports the recordcount property. The Keyset
    cursor or Static cursor types support recordcount property and
    use a serverside cursor location.

    Also, it depends on the provider that your using.

    Third, when you dont specify the cursor type and lock type, the
    defaults are used which are adFordwardOnly and adLockReadOnly.
    Maybe try this, depending on your provider.

    VB Code:
    1. rs.Open "select * from card_Header", objDB.ConnectionString, adOpenKeyset, adLockOptimistic, adCmdText
    Best bet is to search MSDN for "Recordcount" because there
    are allot of situations that can affect the support of the recordcount
    property. For example if your application deletes records in a
    dynaset-type Recordset object, the value of the RecordCount
    property decreases. However, records deleted by other users
    aren't reflected by the RecordCount property until the current
    record is positioned to a deleted record.

    Also, when you work with linked TableDef objects, the
    RecordCount property setting is always – 1.

    This is why I say to read the help file for your particular use.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I was trying to point him in the right direction. I quoted a resolved thread, so I thought that I had it.

  5. #5

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211
    are there any resolved threads already? well thanks for the help.. ur very helpful.. i'll try both your answers a lil later... ill look for that resolved thread if there is any. kindly post the resolved thread if you find it first.. thanks a lot! i mean thank you thank you thank you thank you....
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I think that it was before the use of the checkmark. It ended in "Thank You" or something to that effect. If you search for the quote, then you should find the post.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I quoted brucevde:

    here

    I guess that I assumed that it was resolved. Sorry.

  8. #8

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211
    thanks... just tried your suggestions... it work as i wanted it.. thanks alot... i mean, thank you very much!
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

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