Results 1 to 3 of 3

Thread: Brain dissolve - record count [Resolved]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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:
    1. dim db as database
    2. dim rs as recordset
    3. set db = currentdb
    4. 'error on next line - type mismatch
    5. set rs = db.openrecordset("select * from tablename")
    6. if rs.recordcount > 0 then
    7. ....
    8. else
    9. ....
    10. 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.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    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
    -------------------------------

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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:
    1. Private Function FindExistingRecords() As Boolean
    2. Dim db As Database
    3. Dim rs As Recordset
    4. Dim strSql As String
    5.  
    6. FindExistingRecords = False
    7. strSql = "SELECT * FROM " & mstrLogName '& ";"
    8.  
    9. Set db = CurrentDb
    10. Set rs = db.OpenRecordset(mstrLogName)
    11. rs.MoveLast
    12.  
    13. If rs.RecordCount > 0 Then
    14.     FindExistingRecords = True
    15.     MsgBox (rs.Fields.Count)
    16. End If
    17. 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
  •  



Click Here to Expand Forum to Full Width