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

Display the number of records found

P: 42
Hi guys - one more problem i couldn't figure it out .

I have a form which displays a set of records and i want to display on top of the form the number of the record the user is looking at out of the total records .

I hope u understand what i'm looking for .
for example i want to display something like this

" record : 1 out of 50 found "

i know how to display the total cose is just a count of all records but what about the "1" how do i make it to display and to incremet each time the user clicks to see the next record?

Thanks
May 19 '09 #1
Share this Question
Share on Google+
22 Replies


ADezii
Expert 5K+
P: 8,683
@onyris
You can use the CurrentRecord Property of a Form to identify the Current Record in the Recordset being viewed, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![lblRecordNumber].Caption = "Record Number " & Me.CurrentRecord
  3. End Sub
May 19 '09 #2

NeoPa
Expert Mod 15k+
P: 31,712
This number will not always be predictable. Even if it is, it is not something that will be much help to refer to. I suggest you'd be better off displaying a field, such as the PK, which will uniquely reference the record.

Finding record #X in future will often return a different record, depending on a number of variables.
May 19 '09 #3

P: 42
You can use the CurrentRecord Property of a Form to identify the Current Record in the Recordset being viewed
Thanks man , that's exactly what i needed .
May 19 '09 #4

ADezii
Expert 5K+
P: 8,683
@NeoPa
Just for curiosity NeoPa, how is CurrentRecord not predictable? It corresponds exactly to the Value shown in the Record Number Box on a Form and will also reflect the Absolute Position relative to the Form's Data Source. I realize that it is not a Unique Reference to a specific Record, but that is not why this Property exists.
May 19 '09 #5

NeoPa
Expert Mod 15k+
P: 31,712
@ADezii
Well, the answer's in your question from my perspective.

Deletions (and additions in fact in some cases) can effect which record is where within a particular data source.

A single table can have various indices. Each would reflect a different order, and therefore relative position. This may not effect an individual form in a single instance, but assuming nothing will change is not something I would ever advise.
@ADezii
Exactly why I recommend it not be used that way.
May 19 '09 #6

ADezii
Expert 5K+
P: 8,683
@NeoPa
Sorry NeoPa, but I think you are over-analyzing the concept. Sometimes it is not relevant which Record is where within a particular Data Source, but Record Number X of X Records within the Data Source is. Oh well, always a pleasure.
May 19 '09 #7

NeoPa
Expert Mod 15k+
P: 31,712
You're possibly right ADezii, but that way I avoid possible problems later on. If the problem isn't there all I've lost is a little time analysing in the first place.

As a practice though, I find it helps. At the end of the day, we all need to choose ways we're happiest working with. I'm possibly a tad over-analytical by nature, but I don't remember it getting me into any trouble anywhen.

PS. You know I always enjoy discussing things with you. We may disagree on some things, but that's how ideas get shared. Always beneficial in my view.
May 20 '09 #8

P: 42
Guys , one more question

When the form is loaded is displaying the number of records out of the total records. This is fine , but now when i select a different record from the List box
the current record number remains the same (doesn't change).

I have tried to build an If statement and is not working.I'll put the code below if you could tell me what is wrong.
I am not sure what the index number is if nothig is selected from the listbox.
Expand|Select|Wrap|Line Numbers
  1. if List49.Selected =null
  2. Me![Label37].Caption = Me.CurrentRecord
  3. else 
  4. Me![Label37].Caption = List49.Selected
May 20 '09 #9

ADezii
Expert 5K+
P: 8,683
@onyris
but now when i select a different record from the List box
the current record number remains the same (doesn't change).
Not really sure what you mean.
May 20 '09 #10

P: 42
Not really sure what you mean.
I'll try to explain again.

when the form opens , this is the code used to display current record in the recordset being viewed :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Me![Label37].Caption = Me.CurrentRecord
  3.  
  4. End Sub
The same record set is stored in a List box.
for example the record set contains 3 records
At the begining is displayed
" Record 1 of 3 found"

then when i click on the third record from the listbox to display this
" Record 3 of 3 found"

this is what i want with words
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. if ( nothing selected in the listbox)
  3. Me![Label37].Caption = Me.CurrentRecord
  4. else( get the index number of the selected record and display it )
  5. End Sub
Hope it make sense now , if not let me know and i'll try again.
Sorry about the way i explain the issues.
May 20 '09 #11

ADezii
Expert 5K+
P: 8,683
@onyris
I'm a little slow this Week, no this Month, well actually this Year. In any event, try the following which assumes a List Box named List49 ,a Label Control named Label37, and the MultiSelect Property of the List Box = None:
Expand|Select|Wrap|Line Numbers
  1. 'A ListIndex of -1 indicates that 'No Item was Selected'
  2. If Me![List49].ListIndex = -1 Then
  3.   Me![Label37].Caption = Me.CurrentRecord
  4. Else
  5.   'ListIndex Property is Zero based, so add 1 if necessary
  6.   Me![Label37].Caption = Me![List49].ListIndex + 1
  7. End If
May 20 '09 #12

P: 42
I have tried that and now i get this error :

Compile error: Syntax error on this line

If Me![List49].ListIndex = -1 Then

Any ideea?
May 21 '09 #13

ADezii
Expert 5K+
P: 8,683
@onyris
Is your List Box named List49?
May 21 '09 #14

P: 42
Yes it is i've checked again.
May 21 '09 #15

P: 42
I have added an "end if " at the end and is not giving any errors now , but is not displaying the number on the label.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me![List49].ListIndex = -1 Then
  3. Me![Label37].Caption = Me.CurrentRecord
  4. Else
  5. Me![Label37].Caption = Me![List49].ListIndex + 1
  6. End If
  7. End Sub
Anything wrong with the code?
May 21 '09 #16

ADezii
Expert 5K+
P: 8,683
@onyris
Are you sure that your Label is named Label37, and in fact it is a Label, and not a Text Box Control since a Text Box does not have a Caption Property?
May 21 '09 #17

P: 42
Are you sure that your Label is named Label37, and in fact it is a Label, and not a Text Box Control since a Text Box does not have a Caption Property?
Yes , 100%.

The code is in Form_current().
this is the right place or it should be in the Form_load()?
May 21 '09 #18

ADezii
Expert 5K+
P: 8,683
@onyris
The Form's Current() Event is the right location. Can't understand why it is not working, I've had no problems on this end.
May 22 '09 #19

P: 42
The Form's Current() Event is the right location. Can't understand why it is not working, I've had no problems on this end.
Had a look again over the names and the code , everything is ok .
Why is it not working?
May 22 '09 #20

P: 42
right , i have changed a bit , and on the List49 click event i have added this code:
Expand|Select|Wrap|Line Numbers
  1. Me![Label37].Caption = Me![List49].ListIndex + 1
It is working now.
May 22 '09 #21

NeoPa
Expert Mod 15k+
P: 31,712
Onyris,

How about you put a breakpoint on line #2 and debug (Debugging in VBA) it to find out what's going wrong where. Does this sound like something you'd be interested in?
May 22 '09 #22

ADezii
Expert 5K+
P: 8,683
@onyris
Wasn't that indicated in Post #12?
May 22 '09 #23

Post your reply

Sign in to post your reply or Sign up for a free account.