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

Count records in subform

P: 2
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.caption = 1 'increment by +1 or -1 if me.recordset.movenext or moveprevious
lblTotalRecords.caption = me.recordset.recordcount

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
Feb 13 '08 #1
Share this Question
Share on Google+
2 Replies


puppydogbuddy
Expert 100+
P: 1,923
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.caption = 1 'increment by +1 or -1 if me.recordset.movenext or moveprevious
lblTotalRecords.caption = me.recordset.recordcount

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 YourSubformControl 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:
Expand|Select|Wrap|Line Numbers
  1. Me.YourSubformControl.RecordsetClone.movelast
  2. Me.lblRecords.caption = Me.YourSubformControl.CurrentRecord
  3. Me.lblTotalRecords.caption = Me.YourSubformControl.RecordsetClone.RecordCount
If the above does not work,place a textbox named txtRecordIndicator in the desired location on your main form, and place this code on your Form_Current() event for your main form.
Expand|Select|Wrap|Line Numbers
  1. Me.YourSubformControl.RecordsetClone.movelast
  2. Me.txtRecordIndicator.Value =  Me.YourSubformControl.CurrentRecord & _
  3. " of " & Me.YourSubformControl.RecordsetClone.RecordCount
Feb 13 '08 #2

P: 2
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.RecordsetClone.movelast
Me.lblRecords.caption = Me.CurrentRecord
Me.lblTotalRecords.caption = Me.RecordsetClone.RecordCount

Thank you!
Feb 14 '08 #3

Post your reply

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