By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Error at last record in form while displaying count

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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.