Last Record not found SORT OF (1 Viewer)

mloucel

Member
Local time
Yesterday, 22:25
Joined
Aug 5, 2020
Messages
143
Hello all..
I am trying to relearn programming (NEW JOB) and my boss wants a simple form, I have almost got a few things thru youtube and this forum, but I can't seem to solve this that maybe so easy for many or ALL of you.
Problem:
I have a form with buttons First/Last/Next/Back that go thru records she wants, all is working except...
when I try to check for the last record buttons (commands) NEXT and LAST must be disabled
it does .. sort of....
here is the problem:
When it hit the last record it doesn't do anything, except that if I hit NEXT goes to a BLANK record and then it does find the last and disable the buttons.
so let's say I have 5 records, when I hit 5 it does nothing
but if I hit NEXT it goes to 6 and then it says I found the last record and of course disable the buttons, I need those buttons disabled on 5 not 6
Here is my SIMPLE CODE:

' Last record
If Me.CurrentRecord >= Me.Recordset.RecordCount Then
Me.cmdNext.Enabled = False
Me.cmdLast.Enabled = False
Else
Me.cmdNext.Enabled = True
Me.cmdLast.Enabled = True
End If


Any Ideas what am I doing wrong, everything else is just perfect..

Any help would be greatly appreciated...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:25
Joined
Oct 29, 2018
Messages
21,455
Hi. If it's consistent, then maybe just subtract one to your test. For example:

Code:
If Me.CurrentRecord>=Me.Recordset.RecordCount-1 Then
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:25
Joined
May 7, 2009
Messages
19,229
don't you think you should Test for EOF?
Code:
If Me.RecordSet.EOF Then
Me.cmdNext.Enabled = False
Me.cmdLast.Enabled = False
Me.RecordSet.MovePrevious
Else
Me.cmdNext.Enabled = True
Me.cmdLast.Enabled = True
End If
 

mloucel

Member
Local time
Yesterday, 22:25
Joined
Aug 5, 2020
Messages
143
Hi. If it's consistent, then maybe just subtract one to your test. For example:

Code:
If Me.CurrentRecord>=Me.Recordset.RecordCount-1 Then

Thanks for the suggestion but I found the culprit...

I have another routine that checked when I am trying to ADD a new record
when the condition is FALSE (else) of course the condition is always going to be FALSE unless I press the ADD button so I had to add another IF to avoid the issue... MY BAD.

But hey I am learning and trying to keep my job..
THANKS A MILLION FOR YOUR HELP theDBguy..

NEW code..
If Me.NewRecord Then
Me.cmdNew.Enabled = False
Me.cmdLast.Enabled = False
Me.cmdNext.Enabled = False

' Condition will be always FALSE unless new record
' So we need to test if is not the last record
ElseIf _
Me.CurrentRecord < Me.Recordset.RecordCount Then
Me.cmdNew.Enabled = True
Me.cmdLast.Enabled = True
Me.cmdNext.Enabled = True
End If

end Code...
 

mloucel

Member
Local time
Yesterday, 22:25
Joined
Aug 5, 2020
Messages
143
don't you think you should Test for EOF?
Code:
If Me.RecordSet.EOF Then
Me.cmdNext.Enabled = False
Me.cmdLast.Enabled = False
Me.RecordSet.MovePrevious
Else
Me.cmdNext.Enabled = True
Me.cmdLast.Enabled = True
End If
I'll add that, I didn't know that command Me.Recordset.EOF (I used to program in FOXBASE, so I am learning the hard way to keep my JOB)
THANKS A MILLION..
This little helping tips are going to make me a good programmer again, thank you.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:25
Joined
May 7, 2009
Messages
19,229
there is EOF in Foxbase, foxpro, dbase, etc.
 

mloucel

Member
Local time
Yesterday, 22:25
Joined
Aug 5, 2020
Messages
143
Yes sir
IF eof()
etc
if I do not remember wrong, I think I am going to learn a lot from you..
Respectfully;
Maurice.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:25
Joined
Sep 21, 2011
Messages
14,238
I thought this might become one of your issues.
I have also used Foxpro in the past, and Access works a lot differently.

One of the first things I had to get used to, is that for the most part you edit records directly, not through MemVars as in FP.?

Every form has navigation buttons at the bottom, plus an Add button if you choose to show them.

Some people do like to add their own, but as you are starting out again, you could use those to start with?
Just needs a little training. All my users in my last place of work had no issue using those buttons.?

Just a thought?
 

mloucel

Member
Local time
Yesterday, 22:25
Joined
Aug 5, 2020
Messages
143
I thought this might become one of your issues.
I have also used Foxpro in the past, and Access works a lot differently.

One of the first things I had to get used to, is that for the most part you edit records directly, not through MemVars as in FP.?

Every form has navigation buttons at the bottom, plus an Add button if you choose to show them.

Some people do like to add their own, but as you are starting out again, you could use those to start with?
Just needs a little training. All my users in my last place of work had no issue using those buttons.?

Just a thought?
Thank you kindly for your words, yes Foxbase seemed to be easier, this is a new world to me, I used to do some programming and check whatever fields the EU need to fill with maybe a "while fieldx <> "" " or something like that and check those field give a message force the EU to do it or hit the QUIT button and problem solved, now I need tons of code and subforms and sub code and lots of special commands and I am at lost to do something so simple.
Access is beautiful but learning just in a book is not as simple.
 

Users who are viewing this thread

Top Bottom