Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Record Counter Code Bug
Allan McConnell 
     
4 years ago
I have found some code that I have been using to display the Number of records on the form, and it works very well, that is until there are no records to display or displaying 1 of 1 record. Error 3021( I will include a screen shot below)

I find that this error also occurs where I have a form that allows the user to jump to a record which sets the records to 1 of 1.
Code I am using

Private Sub Form_Current()
    
    Dim rst As Dao.Recordset
    Dim lngCount As Long

    Set rst = Me.RecordsetClone
      
    With rst
        .MoveFirst
        .MoveLast
        lngCount = .RecordCount
    End With
    
    Me.RecordTxtBox = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub
Allan McConnell OP  @Reply  
     
4 years ago

Allan McConnell OP  @Reply  
     
4 years ago
In the above example it is clear there are no records and the (New) is displayed.
I am hoping that there is a line of code to trap any chance of it trying to display any record if it is Null.
I do not know enough about code yet to be able to know where to start looking.
Allan McConnell OP  @Reply  
     
4 years ago
Sorry should have said... Trap any error bug where there are no records ... may be a On Error code of sorts?
Allan McConnell OP  @Reply  
     
4 years ago

Adam Schwanz  @Reply  
           
4 years ago
Why not just do

lngcount=Recordset.Recordcount

and erase everything else? If you're just trying to get the current number of records in the recordset.
Private Sub Form_Current()
    Dim lngCount As Long    
    Me.RecordTxtBox = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub

Adam Schwanz  @Reply  
           
4 years ago
Could get rid of lngcount too actually, just simply this

Me.RecordTxtBox = "Record " & Me.CurrentRecord & " of " & Recordset.Recordcount
Adam Schwanz  @Reply  
           
4 years ago
Dont think you need the Me. either ;)

RecordTxtBox = "Record " & CurrentRecord & " of " & Recordset.Recordcount
Allan McConnell OP  @Reply  
     
4 years ago
Thank you. Thank you Thank you. Much appreciated.
That works very well and no error now. I can now safely put this back into other forms that I has troubles with, as the little record selector at the bottom of the screen, while good are too small for some forms.

That I am leading up to earning more about VB code as I have never really had much to do with programming.
I tried to analyze the code and work it out myself, but just didn't know what the coded was saying and never thought of stripping bits off the code.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 11:22:13 AM. PLT: 1s