Count records in subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gmlscripts
    New Member
    • Feb 2008
    • 2

    Count records in subform

    I have a subform that shows images (0, 1, 2, ...etc) linked to a main form. I would like to display the current record number of total number of records for each linked record on the main form. (ie "Image" X " of " Y).

    My problem is that as I move between records on my main form, the record information on the subform does not change. I set the subform to NOT show the navigation button (I put command buttons on the form with that functionality). I have tried:
    Initially:

    lblRecords.capt ion = 1 'increment by +1 or -1 if me.recordset.mo venext or moveprevious
    lblTotalRecords .caption = me.recordset.re cordcount

    The values get really messed up as I navigate through the sub-form and main form. I am very frustrated because I thought this would be simple.

    I am a VBA neophyte, so please use small words. :-)

    Thanks in Advance
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by gmlscripts
    I have a subform that shows images (0, 1, 2, ...etc) linked to a main form. I would like to display the current record number of total number of records for each linked record on the main form. (ie "Image" X " of " Y).

    My problem is that as I move between records on my main form, the record information on the subform does not change. I set the subform to NOT show the navigation button (I put command buttons on the form with that functionality). I have tried:
    Initially:

    lblRecords.capt ion = 1 'increment by +1 or -1 if me.recordset.mo venext or moveprevious
    lblTotalRecords .caption = me.recordset.re cordcount

    The values get really messed up as I navigate through the sub-form and main form. I am very frustrated because I thought this would be simple.

    I am a VBA neophyte, so please use small words. :-)

    Thanks in Advance
    If I understood you correctly, you want the counts for your subform records while moving thru different records on the main form. Try this in the Current event of your main form. You have to replace illustrative object names like YourSubformCont rol with their actual names in your application. I am also assuming your label captions are on the main form. If these assumptions are not correct, the code will have to change accordingly:
    Code:
    Me.YourSubformControl.RecordsetClone.movelast
    Me.lblRecords.caption = Me.YourSubformControl.CurrentRecord
    Me.lblTotalRecords.caption = Me.YourSubformControl.RecordsetClone.RecordCount
    If the above does not work,place a textbox named txtRecordIndica tor in the desired location on your main form, and place this code on your Form_Current() event for your main form.
    Code:
    Me.YourSubformControl.RecordsetClone.movelast
    Me.txtRecordIndicator.Value =  Me.YourSubformControl.CurrentRecord & _
    " of " & Me.YourSubformControl.RecordsetClone.RecordCount

    Comment

    • gmlscripts
      New Member
      • Feb 2008
      • 2

      #3
      Hah! Perfect and so much simpler than my attempted solutions (plus it works). I actually wanted the count and total records information to be on the sub-form, not the main form. Changing the code was an easy fix.

      me.RecordsetClo ne.movelast
      Me.lblRecords.c aption = Me.CurrentRecor d
      Me.lblTotalReco rds.caption = Me.RecordsetClo ne.RecordCount

      Thank you!

      Comment

      Working...