Results 1 to 3 of 3
  1. #1
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22

    Record count in Access table using VBA

    I'm trying to get the record count of a table, and if count is greater than 17, create a new table.

    Code:
    Dim rst As DAO.Recordset
    strSQL = "Select * from SKUS"
    Set rst = db.OpenRecordset(strSQL)
    
    If rst.RecordCount > 17 Then
        Set tdf = db.CreateTableDef("161-0363")
    
        Set fld = tdf.CreateField("SKUS", dbText, 30)
        tdf.Fields.Append fld
    
        Set fld = tdf.CreateField("Count", dbInteger)
        tdf.Fields.Append fld
    
        db.TableDefs.Append tdf
    End If
    This code doesn't create a new table, but when I change the if statement to this, it works:

    Code:
    ...
    If rst.RecordCount > 0 Then
        Set tdf = db.CreateTableDef("161-0363")
    ...
    So the RecordCount is returning 1, I think. Why is this happening? I know for sure the table has 18 rows in it.


    Can anyone help me out?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you may have to do something like

    rst.movelast

    then perform your

    if rst.recordcount > 17 if loop

  3. #3
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22
    Thanks, that worked!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Record Count/Change
    By TPH in forum Queries
    Replies: 3
    Last Post: 06-21-2011, 03:19 PM
  2. Record Count
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 12-02-2010, 09:22 AM
  3. Display record count
    By jgelpi16 in forum Reports
    Replies: 5
    Last Post: 11-30-2010, 09:02 PM
  4. remove record count
    By theITguy in forum Access
    Replies: 1
    Last Post: 03-06-2009, 06:22 PM
  5. Form Record Count
    By Texaine in forum Forms
    Replies: 0
    Last Post: 10-19-2006, 09:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums