|
-
Aug 30th, 2012, 05:13 AM
#1
Thread Starter
Fanatic Member
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
-
Aug 30th, 2012, 06:59 AM
#2
New Member
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))
-
Aug 30th, 2012, 07:44 AM
#3
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
-
Aug 30th, 2012, 07:50 AM
#4
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.
-
Aug 30th, 2012, 09:15 AM
#5
Thread Starter
Fanatic Member
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
-
Aug 30th, 2012, 09:28 AM
#6
Thread Starter
Fanatic Member
Re: Rs recordcount not working?
-
Aug 30th, 2012, 11:55 AM
#7
Re: Rs recordcount not working?
Did it have to do with cursor location?
-
Aug 30th, 2012, 03:41 PM
#8
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.
-
Aug 30th, 2012, 03:54 PM
#9
Frenzied Member
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
-
Aug 30th, 2012, 03:56 PM
#10
Re: Rs recordcount not working?
Yea, I didn't notice he was calling OpenRecordset. That sure ins't ADO.
-
Aug 31st, 2012, 09:43 PM
#11
Re: Rs recordcount not working?
Why don't you just use COUNT(*) if you want to count how many record a recordset returns?
-
Sep 1st, 2012, 01:29 AM
#12
Re: Rs recordcount not working?
 Originally Posted by dee-u
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|