|
-
Feb 25th, 2004, 12:12 PM
#1
Thread Starter
Frenzied Member
Brain dissolve - record count [Resolved]
How do I find out the recordcount of a table? I don't know if my brain's dissolving or a problem with Access (help files are disappearing, so maybe...)
I had
VB Code:
dim db as database
dim rs as recordset
set db = currentdb
'error on next line - type mismatch
set rs = db.openrecordset("select * from tablename")
if rs.recordcount > 0 then
....
else
....
end if
I swear this works in at least Access 97, but not in 2000. I know this is simple but I'm blanking out on it. Thanks.
Last edited by salvelinus; Feb 26th, 2004 at 10:01 AM.
-
Feb 26th, 2004, 03:17 AM
#2
Addicted Member
Try this :-
set rs = db.openrecordset("tablename")
rs.MoveLast
if rs.recordcount > 0 then
Sometimes I find problems passing arguments requiring string concatenation to a function. It seems safer to use a string variable. eg.
set rs = db.openrecordset(MyString)
Regards
BrianB
-------------------------------
-
Feb 26th, 2004, 09:06 AM
#3
Thread Starter
Frenzied Member
I'm wondering if the problem is with Access 2000 being corrupted. The entire function is below. I keep getting a type mismatch at the Set rs = db.OpenRecordset(...) line. I've substituted strSQL, the actual table name, mstrLogName (the table name in a variable) in the argument, no luck. A watch on CurrentDb and db right before that line shows correct types, but no values. This is a form in a database called Test. This is really confusing.
Thanks for any help.
[edit]
Resolved. There were references to both dao and ado. I'd checked references, but to make sure they were there, not that they weren't. Declaring rs as dao.recordset fixed the problem.
[/edit]
VB Code:
Private Function FindExistingRecords() As Boolean
Dim db As Database
Dim rs As Recordset
Dim strSql As String
FindExistingRecords = False
strSql = "SELECT * FROM " & mstrLogName '& ";"
Set db = CurrentDb
Set rs = db.OpenRecordset(mstrLogName)
rs.MoveLast
If rs.RecordCount > 0 Then
FindExistingRecords = True
MsgBox (rs.Fields.Count)
End If
End Function
Last edited by salvelinus; Feb 26th, 2004 at 10:03 AM.
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
|