Results 1 to 27 of 27

Thread: Getting RecordCount [Resolved] (almost)

Hybrid View

  1. #1
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Getting RecordCount

    But doesnt it work for the .LastRecord = .RecordCount?
    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

  2. #2

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Getting RecordCount

    nope. just works with the -1

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Getting RecordCount

    It works for mine so I double checked in the help file and this its what I found.
    If Microsoft Word cannot determine the number of records in a data source, the RecordCount property will return a value of -1
    So it may depend on the way datasource was setup or if its a complex query???
    What is your datasource? .odc?
    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
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Getting RecordCount

    I've used this very non-standard trick at times to arrive at a recordcount - if the number of rows in the table is low - it won't matter that this is a ugly query...

    Code:
    Select [First Name], [Last Name], [Mailing Address], City, State, Zip
    ,(Select Count(*) From [My Temp]) From [MyTemp]
    Thus getting the recordcount as a column in the recordset itself...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Getting RecordCount

    It actually works for the complex query that isn't part of the mailmerge. (the one that sends email or printer output) I guess that I'll have to do a separate query to get the count. That's what I was trying to avioid if it wasn't necessary.

    Thanks

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Getting RecordCount

    If you are going to go the separate query route, then my technique guarantees that the recordcount will truly match the row count in the "data" recordset. If you do two separate queries, then you could run the risk of row counts changing during the operation. We would have that happen in our applications - they load lots of rows in a given day!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Getting RecordCount

    How do I refer to the Count() field in my RS ? I forgot that I had already done it with the complex query. Now I need it for the simple query. If I can add the count like szlammy said, I'd like to do that.

    EDIT: I have this

    VB Code:
    1. rs.Open "Delete TempTable .* from TempTable ", cn, adOpenKeyset, adLockOptimistic, adCmdText
    2.  
    3.   rs.Open "INSERT INTO TempTable (RecCount) " & _
    4.      "SELECT  Count(*)" & _
    5.      "From FarmingTemp", cn, adOpenKeyset, adLockOptimistic, adCmdText
    6.   RecCount = rs.Fields(1)

    So how do I get it back out. I've also tried RecCount = rs.fields("RecCount") but that returns an error.
    Last edited by dglienna; Feb 21st, 2005 at 04:37 PM.

  8. #8

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Getting RecordCount

    I think I figured it out:

    VB Code:
    1. rs.Open "select RecCount from TempTable", cn, adOpenKeyset, adLockOptimistic, adCmdText
    2.  
    3.   RecCount = rs.Fields("RecCount")

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