473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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.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
2 18551
puppydogbuddy
1,923 Expert 1GB
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
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

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

Similar topics

3
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
0
by: Lauren Quantrell | last post by:
I'm using SQL Server backend on an Access 2K front end. I populate a subform: Forms!myForm.myChild.Form.RecordSource = "myStoredProcedureName" On that form is a control where the controlsource is...
0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
4
by: misscrf | last post by:
On a main form, there is a subform. I want to make a field that will show how many records there are within that subform. Count on the pk, where the subform's fk = the main form pk.. or something...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
11
by: Beany | last post by:
Hi, Can some please provide me with the code for counting records in a subform and displaying it in a textbox? Does this code go into the control source of the textbox? My subform is called...
0
by: jwbird | last post by:
I have a main form with multiple Subforms that are all displaying Datasheet information related to the Main form record. When I make changes/adds to the records(s) in the subform and tab to another...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.