Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count records entered into a form

Status
Not open for further replies.

jspence

Technical User
Mar 5, 2003
3
US
Hey Everyone,

I'm trying to write code that will populate a textbox on my main form with the total number of new records added to a subform. For example, My table has over 14000 records in it,If I enter 10 new ones, I want to see the #10. The code I have now is showing 14000. Is it even possible?

Thanks
Jason
 
It's not as easy as finding the right property and using it.

I'd recommend adding a count variable to the form module:
Code:
Private lngRecCount as Long

Then on the Form_Open() event:

Code:
' set ("lngRecCount = Me.RecordsetClone.RecordCount")
' recordcount is not accurate unless you're at the 
' last record in the set.
lngReCount = countRecordsetClone()

Actually, I will move this feature to a new sub.
Code:
Private Function countRecordsetClone() As Long
    Dim rs as DAO.Recordset

    Set rs = Me.Recordsetclone

    If Not rs.EOF Then
        rs.MoveLast
    End If

    If rs.BOF And rs.EOF Then
        countRecordsetClone = 0
    Else
        countRecordsetClone = rs.RecordCount
    End If

    rs.Close
End Sub

Then, on the Form_AfterUpdate():
Code:
txtNewRecordCountTextBox.Value = countRecordsetClone() - lngRecCount

This should keep a count of how many new records there are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top