467,150 Members | 1,192 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,150 developers. It's quick & easy.

Error at last record in form while displaying count

I have a label on my form lblCount and the following code in my form for
displaying a record count:

Private Sub Form_Current()
Me.RecordsetClone.Bookmark = Me.Bookmark
Me!lblCount.Caption = Me.RecordsetClone.AbsolutePosition + 1
End Sub

It works fine until I page to the last record and I get:

Run-time Error 3021, No Current Record

How to fix?

Robert
Nov 13 '05 #1
  • viewed: 3323
Share:
2 Replies
"Robert" <pr**********@yahoo.com> wrote in message
news:3Q******************@fe02.lga
I have a label on my form lblCount and the following code in my form for
displaying a record count:

Private Sub Form_Current()
Me.RecordsetClone.Bookmark = Me.Bookmark
Me!lblCount.Caption = Me.RecordsetClone.AbsolutePosition + 1
End Sub

It works fine until I page to the last record and I get:

Run-time Error 3021, No Current Record

How to fix?

Robert

It work fine until you don't click NewRecord when you are at
last or Previous when you are at first...!!!

You lose Error gestion...?

First you know that when you go to next when you
are at last the Absolute position give error, but
the label need to show some value.
This value is the RecordCount+1, but only if you
are on NewRecord, in the other case, if err.Number=3021
you need Resume Next.

Try with this, i write it without test, so good work.

Private Sub Form_Current()
On Error Goto Err_Get

Me.RecordsetClone.Bookmark = Me.Bookmark
Me!lblCount.Caption = Me.RecordsetClone.AbsolutePosition + 1

Err_Gest:
If Err.Number=3021 then
If me.NewRecord then
Me!lblCount.Caption=Me.RecordsetClone.RecordCount+ 1
Else
Resume Next
End if
Else
msgbox Err.Number & " " & err.Description
End if
Exit sub

@Alex
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Nov 13 '05 #2
Thanks for your help. I think I found a much simpler solution. In the case
where there is no need for a record total

Me!lblCount.Caption = Me.CurrentRecord

shoule be sufficient or you could use

If Not Me.NewRecord Then
Me!lblCount.Caption = Me.CurrentRecord
Else
Me!lblCount.Caption = ""
End If

Robert

"Alessandro Baraldi" <ik****@libero.it> wrote in message
news:28***********************************@mygate. mailgate.org...
"Robert" <pr**********@yahoo.com> wrote in message
news:3Q******************@fe02.lga
I have a label on my form lblCount and the following code in my form for
displaying a record count:

Private Sub Form_Current()
Me.RecordsetClone.Bookmark = Me.Bookmark
Me!lblCount.Caption = Me.RecordsetClone.AbsolutePosition + 1
End Sub

It works fine until I page to the last record and I get:

Run-time Error 3021, No Current Record

How to fix?

Robert

It work fine until you don't click NewRecord when you are at
last or Previous when you are at first...!!!

You lose Error gestion...?

First you know that when you go to next when you
are at last the Absolute position give error, but
the label need to show some value.
This value is the RecordCount+1, but only if you
are on NewRecord, in the other case, if err.Number=3021
you need Resume Next.

Try with this, i write it without test, so good work.

Private Sub Form_Current()
On Error Goto Err_Get

Me.RecordsetClone.Bookmark = Me.Bookmark
Me!lblCount.Caption = Me.RecordsetClone.AbsolutePosition + 1

Err_Gest:
If Err.Number=3021 then
If me.NewRecord then
Me!lblCount.Caption=Me.RecordsetClone.RecordCount+ 1
Else
Resume Next
End if
Else
msgbox Err.Number & " " & err.Description
End if
Exit sub

@Alex
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Victor | last post: by
reply views Thread by Morten Gulbrandsen | last post: by
1 post views Thread by feck | last post: by
2 posts views Thread by jthep | last post: by
15 posts views Thread by Lawrence Krubner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.