Results 1 to 27 of 27

Thread: Getting RecordCount [Resolved] (almost)

Hybrid View

  1. #1

    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.

  2. #2

    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")

  3. #3

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

    Re: Getting RecordCount

    Still like to know how to use the example that slammy suggested.

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

    Re: Getting RecordCount

    Quote Originally Posted by dglienna
    Still like to know how to use the example that slammy suggested.
    I am not familiar with the WORD object you are using - it appears that you don't have access to the RS from the code you posted...

    Where is the execute or open of the recordset?

    *** 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

    word takes care of it all.

    it I do a separate query, how do I access the count()? Where is it placed?
    The only way I could get a count is my later code that placed it into a seperate field in a new table. If I use it like you did? How do I retrieve it?

    I think that I see that you are putting it into an extra field in the table? I'm not sure, though.

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

    Re: Getting RecordCount

    Code:
    rs.Open "SELECT  Count(*) From FarmingTemp" _
        , cn, adOpenKeyset, adLockOptimistic, adCmdText
    RecCount = rs.Fields(0)
    OR

    Code:
    rs.Open "SELECT  Count(*) "RecCount" From FarmingTemp" _
        , cn, adOpenKeyset, adLockOptimistic, adCmdText
    RecCount = rs.Fields("RecCount")

    *** 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

    No, I meant from THIS CODE:
    VB Code:
    1. Select [First Name], [Last Name], [Mailing Address], City, State, Zip
    2. ,(Select Count(*) From [My Temp]) From [MyTemp]

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

    Re: Getting RecordCount

    Actually - I didn't mean to leave the FROM as FARMINGTEMP - the FROM should be the real table you are getting this data from.

    There is no need for a temporary table in this example.

    *** 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

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