Display the number of records found

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onyris
    New Member
    • Aug 2008
    • 42

    Display the number of records found

    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
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by onyris
    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
    You can use the CurrentRecord Property of a Form to identify the Current Record in the Recordset being viewed, as in:
    Code:
    Private Sub Form_Current()
      Me![lblRecordNumber].Caption = "Record Number " & Me.CurrentRecord
    End Sub

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      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.

      Comment

      • onyris
        New Member
        • Aug 2008
        • 42

        #4
        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 .

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by NeoPa
          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.
          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.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Originally posted by ADezii
            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.
            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.
            Originally posted by ADezii
            I realize that it is not a Unique Reference to a specific Record, but that is not why this Property exists.
            Exactly why I recommend it not be used that way.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by NeoPa
              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.

              Exactly why I recommend it not be used that way.
              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.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                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.

                Comment

                • onyris
                  New Member
                  • Aug 2008
                  • 42

                  #9
                  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.
                  Code:
                  if List49.Selected =null
                  Me![Label37].Caption = Me.CurrentRecord
                  else 
                  Me![Label37].Caption = List49.Selected
                  Last edited by NeoPa; May 20 '09, 10:57 PM. Reason: Please use the [CODE] tags provided

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by onyris
                    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.



                    if List49.Selected =null
                    Me![Label37].Caption = Me.CurrentRecor d
                    else
                    Me![Label37].Caption = List49.Selected
                    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.

                    Comment

                    • onyris
                      New Member
                      • Aug 2008
                      • 42

                      #11
                      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 :
                      Code:
                      Private Sub Form_Current()
                      Me![Label37].Caption = Me.CurrentRecord
                      
                      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
                      Code:
                      Private Sub Form_Current()
                      if ( nothing selected in the listbox)
                      Me![Label37].Caption = Me.CurrentRecord
                      else( get the index number of the selected record and display it )
                      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.
                      Last edited by NeoPa; May 20 '09, 10:59 PM. Reason: Please use the [CODE] tags provided

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Originally posted by onyris
                        I'll try to explain again.

                        when the form opens , this is the code used to display current record in the recordset being viewed :
                        Code:
                        Private Sub Form_Current()
                        Me![Label37].Caption = Me.CurrentRecord
                        
                        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
                        Code:
                        Private Sub Form_Current()
                        if ( nothing selected in the listbox)
                        Me![Label37].Caption = Me.CurrentRecord
                        else( get the index number of the selected record and display it )
                        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.
                        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:
                        Code:
                        'A ListIndex of -1 indicates that 'No Item was Selected'
                        If Me![List49].ListIndex = -1 Then
                          Me![Label37].Caption = Me.CurrentRecord
                        Else
                          'ListIndex Property is Zero based, so add 1 if necessary
                          Me![Label37].Caption = Me![List49].ListIndex + 1
                        End If

                        Comment

                        • onyris
                          New Member
                          • Aug 2008
                          • 42

                          #13
                          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?

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            Originally posted by onyris
                            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?
                            Is your List Box named List49?

                            Comment

                            • onyris
                              New Member
                              • Aug 2008
                              • 42

                              #15
                              Yes it is i've checked again.

                              Comment

                              Working...