Solved Custom record counter and navigation buttons (1 Viewer)

tihmir

Registered User.
Local time
Today, 05:39
Joined
May 1, 2018
Messages
257
Hi аll,
whenever I try to use this code and set Navigation Buttons to "No" (Property Sheet) it says record 1 of 1 no matter how many records there are and the nav buttons do not work.
What is wrong with the code and can it be made working?
Code:
Private Sub Form_Current()
    
    Me!txtResult = CurrentRecord & " of " & Me.RecordsetClone.RecordCount
    Me.Caption = Me.txtResult

On Error Resume Next
' These If Statements manage the Navigation Buttons
  If Me.CurrentRecord = 1 Then
     Me.cmd_Back.Enabled = False
     Me.cmd_First.Enabled = False
  Else
     Me.cmd_Back.Enabled = True
     Me.cmd_First.Enabled = True
  End If
  If Me.CurrentRecord = Me.Recordset.RecordCount Then
      Me.cmd_Last.Enabled = False
  Else
     Me.cmd_Last.Enabled = True
  End If
  If Me.CurrentRecord >= Me.Recordset.RecordCount Then
     Me.cmd_Next.Enabled = False
  Else
     Me.cmd_Next.Enabled = True
  End If
End Sub
 

Attachments

  • Database_v1.accdb
    2.1 MB · Views: 484

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,467
Hi. It could just be me, but I think your file may be corrupted. Try starting from scratch with a new blank db file (just to test your code).
 

tihmir

Registered User.
Local time
Today, 05:39
Joined
May 1, 2018
Messages
257
Hi. It could just be me, but I think your file may be corrupted. Try starting from scratch with a new blank db file (just to test your code).
hi, theDBguy. Thanks for replay. The file is absolutely new. I made it just for the example. If I set the Navigation Buttons to "Yes" (Property Sheet) everything works perfect.
P.S. Is there another way to load a blank form except Data entry set to "Yes"?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,467
hi, theDBguy. Thanks for replay. The file is absolutely new. I made it just for the example. If I set the Navigation Buttons to "Yes" (Property Sheet) everything works perfect.
P.S. Is there another way to load a blank form except Data entry set to "Yes"?
Hi. I don't know what's wrong with me then. Every time I try to open your form, I get this error message.

error.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:39
Joined
May 21, 2018
Messages
8,527
If you are going to build this then the controls should be in a subform. Then you can reuse this on any form with no code modification. Just reference the parent form.
 

tihmir

Registered User.
Local time
Today, 05:39
Joined
May 1, 2018
Messages
257
Here is the new db v1 guys
 

Attachments

  • NEW DB v1.accdb
    800 KB · Views: 483

Isaac

Lifelong Learner
Local time
Today, 05:39
Joined
Mar 14, 2017
Messages
8,777
Unfortunately I am getting the same error. Did you re-create the form from scratch?
 

tihmir

Registered User.
Local time
Today, 05:39
Joined
May 1, 2018
Messages
257
If you are going to build this then the controls should be in a subform. Then you can reuse this on any form with no code modification. Just reference the parent form.
Thanks, MajP, but can I build this controls in a main form?
 

Micron

AWF VIP
Local time
Today, 08:39
Joined
Oct 20, 2018
Messages
3,478
I don't know the reason, but I think I found the problem. Change the name of АnotherТaskID to text205 or any similar name. Don't use Task, Another or ID in any name.
I've decompiled/compiled, performed a c/r, replaced the textbox with a new one on a copy of the form and set the same control source, all to no avail if the control name contains one or more of those words. I haven't done a detailed test regarding the words so the only thing I can say for sure that in my first db copy, all is ok if the control is a name that's totally different. Maybe it has something to do with Name Auto Correct options, which are enabled.
 

Cronk

Registered User.
Local time
Today, 22:39
Joined
Jul 4, 2013
Messages
2,772
I imported all the objects into a blank database (Access 365) and it opens.
 

Micron

AWF VIP
Local time
Today, 08:39
Joined
Oct 20, 2018
Messages
3,478
I don't know what else is wrong, but there are other issues such as if you step through the code the record count control does get updated (but it has weird text that it gets from the code) but if you let it run it fails and locks the buttons regardless of the record count. I don't have time to spend on that at the moment, and if OP is to start over as MajP suggests, it would be pointless anyway. Seems kind of strange to me to set the form caption to what's in the nav counter.
 

Users who are viewing this thread

Top Bottom