Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    11

    Unanswered: record counting function

    Aim trying to write a function which will count the records in a table.

    I have pieced some code together from books, and help files, but I can't get it to work. It always returns a value of 1.

    Where am I going wrong? Is there a better way of doing it?

    =====================================
    Public Function CountMyRecords() As Long
    Dim rstMyData As DAO.Recordset
    Dim intMyRecords As Integer

    Set rstMyData = CurrentDb.OpenRecordset("SELECT MyField FROM MyTable")

    countoffers = rstMyData.RecordCount

    rstMyData .Close
    End Function
    =====================================

    Thanks.

    Nick Holmes

  2. #2
    Join Date
    Feb 2003
    Location
    Wichita,KS
    Posts
    44
    Try this

    rstMyData.MoveLast
    countoffers = rstMyData.RecordCount

  3. #3
    Join Date
    Mar 2003
    Posts
    11
    Originally posted by ray705
    Try this

    rstMyData.MoveLast
    countoffers = rstMyData.RecordCount
    Perfect! Thank you.

  4. #4
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820

    Re: record counting function

    your also short the return statement

    try

    Public Function CountMyRecords() As Long
    Dim rstMyData As DAO.Recordset

    Set rstMyData = CurrentDb.OpenRecordset("SELECT [holeid] FROM tblHoles")
    rstMyData.MoveLast

    CountMyRecords = rstMyData.RecordCount

    rstMyData.Close
    End Function

    Originally posted by Nick Holmes
    Aim trying to write a function which will count the records in a table.

    I have pieced some code together from books, and help files, but I can't get it to work. It always returns a value of 1.

    Where am I going wrong? Is there a better way of doing it?

    =====================================
    Public Function CountMyRecords() As Long
    Dim rstMyData As DAO.Recordset
    Dim intMyRecords As Integer

    Set rstMyData = CurrentDb.OpenRecordset("SELECT MyField FROM MyTable")

    countoffers = rstMyData.RecordCount

    rstMyData .Close
    End Function
    =====================================

    Thanks.

    Nick Holmes
    Last edited by m.timoney; 03-11-03 at 11:29.
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

Posting Permissions

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