Results 1 to 12 of 12

Thread: Rs recordcount not working?

  1. #1
    Fanatic Member
    Join Date
    May 09
    Posts
    868

    Rs recordcount not working?

    Hi guys, I am trying to show the number of records in my database...

    how ever this is not working



    Code:
    Set rs = db.OpenRecordset("SELECT * FROM `Leads` WHERE `CurrentStatus` = " & "'" & opened & "' AND `Agent` = " & "'" & Combo1.Text & "'")
    Label10.Caption = rs.RecordCount
    rs.Close

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: Rs recordcount not working?

    Label10.caption requires a STRING. RS.Recordcount is an INTEGER. You will have to convert it to a STRING (str(rs.recordcount))

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,659

    Re: Rs recordcount not working?

    No... that's not it at all... it'll do an implicit conversion (it shouldn't have to, you should be doing an explicit conversion, but that's besides the point) but that's not the problem.

    Your posts contains two problems. I'll address the first. Saying "this is not working" with out telling us what isn't working does us all a disservice. First it forces us to guess what the problem is, just like dennis did... it also wastes your time reading useless posts like mine. It also wastes our time writing useless posts like this one in an effort to draw out the problem. Do you walk in to the doctor's office and say "it hurts" when they ask you what's wrong? No. Usually you'll go into a story about how you and your friends were biking, you hit a rock, fall off and broke your arm. Just like that's valuable information to the doc, knowing what's wrong with your code is valuable information to us. The fact that the code doesn't work is like saying water's wet. Well Duh... that's obvious... or you wouldn't be posting here. So what does "it doesn't work" mean? Did your toaster suddenly blow up? Did your door fall off the hinges? Did your fingers suddenly fall off? I'm a personal fan of that last one... it's the only thing I can think of for the lack of information in posts like these.

    Fortunately, I know what the problem is... you have eels in your hover craft. And even more fortunately, I have a guide in my signature block that explains how to remove those pesky eels.

    As for the second problem, I think I suspect what the problem with your code is, but I don't want to waste any more of your time or my time until you can provide more details... for all I know it could be a red herring. Unfortunately I only have a guide for eels, not red herring.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  4. #4
    Fanatic Member
    Join Date
    Mar 09
    Posts
    719

    Re: Rs recordcount not working?

    Try rs.MoveLast and rs.MoveFirst before accessing the RecordCount.

    BTW, those ` characters around the table & field names are unnecessary unless they have spaces in them.

  5. #5
    Fanatic Member
    Join Date
    May 09
    Posts
    868

    Re: Rs recordcount not working?

    Basically when I say it does not work... It means that label11.caption becomes "0"

    so it's basically not counting how many records there is.

    Thanks

  6. #6
    Fanatic Member
    Join Date
    May 09
    Posts
    868

    Re: Rs recordcount not working?

    no worries. fixed it.

  7. #7
    PowerPoster
    Join Date
    Jun 01
    Location
    Trafalgar, IN
    Posts
    3,440

    Re: Rs recordcount not working?

    Did it have to do with cursor location?

  8. #8
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: Rs recordcount not working?

    I think it is using DAO, been a long time since I have used DAO but I do remember needing to do a move last to get an accurate recordcount back in VB5.

    You really should be using ADO rather than the old DAO routines.

  9. #9
    Frenzied Member
    Join Date
    Jan 09
    Location
    Watch Window(Shift+f9)
    Posts
    1,431

    Re: Rs recordcount not working?

    Did it have to do with cursor location?
    yes,Try the following way .
    Code:
    
    rs.cursorlocation=aduseclient
    Set rs = db.OpenRecordset("SELECT * FROM `Leads` WHERE `CurrentStatus` = " & "'" & opened & "' AND `Agent` = " & "'" & Combo1.Text & "'")
    Label10.Caption = rs.RecordCount
    rs.Close
    
    or
    
    rs.cursorlocation=aduseclient
    Set rs = db.OpenRecordset("SELECT * FROM `Leads` WHERE `CurrentStatus` = " & "'" & opened & "' AND `Agent` = " & "'" & Combo1.Text & "'")
    rs.movefirst
    rs.movelast
    Label10.Caption = rs.RecordCount
    rs.Close

  10. #10
    PowerPoster
    Join Date
    Jun 01
    Location
    Trafalgar, IN
    Posts
    3,440

    Re: Rs recordcount not working?

    Yea, I didn't notice he was calling OpenRecordset. That sure ins't ADO.

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 05
    Location
    Philippines
    Posts
    10,233

    Re: Rs recordcount not working?

    Why don't you just use COUNT(*) if you want to count how many record a recordset returns?

  12. #12
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,157

    Re: Rs recordcount not working?

    Quote Originally Posted by dee-u View Post
    Why don't you just use COUNT(*) if you want to count how many record a recordset returns?
    For example:
    Code:
    Set rs = db.OpenRecordset("SELECT COUNT(*) AS OpenLeads FROM `Leads` WHERE `CurrentStatus` = " & "'" & opened & "' AND `Agent` = " & "'" & Combo1.Text & "'")
    Label10.Caption = rs![OpenLeads]
    rs.Close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •