Hi! can this be done..I’m trying to create a query that numbers all the row-records that appear for an individidual ID; i.e. “1-4 0r 6” if that is how many records are available on a particular transaction. Any help is appreciated…:-)
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Numbering Rows in a query by an ID records
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Numbering Rows in a query by an ID records
- This topic has 22 replies, 4 voices, and was last updated 15 years, 6 months ago.
AuthorTopicWSLastcall
AskWoody LoungerOctober 28, 2009 at 1:14 pm #463509Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody LoungerOctober 28, 2009 at 2:00 pm #1183491Although it is possible to number rows in a query, it is tricky and not very efficient. It’s better to do this in a report:
– Create a text box with control source =1
– Set the Running Sum property of the text box to Over All if you want to number all records from 1 to (the number of records).
– Set the Running Sum to Over Groups if you want the numbering to restart at 1 at each grouping level of the report. -
WSLastcall
AskWoody LoungerOctober 28, 2009 at 2:07 pm #1183493Although it is possible to number rows in a query, it is tricky and not very efficient. It’s better to do this in a report:
– Create a text box with control source =1
– Set the Running Sum property of the text box to Over All if you want to number all records from 1 to (the number of records).
– Set the Running Sum to Over Groups if you want the numbering to restart at 1 at each grouping level of the report.The reason I asked is because I need to place the data from the query into a table by using an append query. This table is subordinate to another table which has the header information. Can I perform your recommendation in a form.
-
WSAndrewKKWalker
AskWoody LoungerOctober 28, 2009 at 2:11 pm #1183494The reason I asked is because I need to place the data from the query into a table by using an append query. This table is subordinate to another table which has the header information.
Can you expand on this with a bit of detail of tables, fields, relationships and
which tables/fields are to be updated.
Also the values. Your 1-4 0r 6 was a bit confusing to follow. -
WSHansV
AskWoody LoungerOctober 28, 2009 at 2:14 pm #1183495Your 1-4 0r 6 was a bit confusing to follow.
It’s like 25 or 6 to 4…
-
WBell
AskWoody_MVP -
WSLastcall
AskWoody LoungerOctober 28, 2009 at 3:16 pm #1183505It’s like 25 or 6 to 4…
🙂 No worries. The header table has: a one to many relationship to the detail table. Fields: (key-no duplicates)-BillNo, PersonID,InvDate,year, cycle
subordinate table to Header: AcctAssets has fields: (key-no duplicate)-AcctNo,BillNo,GroupID,AcctInfo,Amt, Notes.
I would like the query to get the personID and provide how many AcctNo records under that BillNo before appending the datas to the table.
Third table is subordinate to AcctAssets and will need the same as the previous table: HoursOnJob has fields: (key-no duplicate)-SubAcctNo, AcctNo, BillNo, position, abbr, hours, rate, Amt.
So in theory:
-Header will have one row of a BillNo with the main total of all subordinates.
-AcctAssets will have how many accts (AcctNo) the BillNo used with their respective totals.
-HoursOnJob will then break it down by SubAcctNo used in AcctNo on a BillNo with hours and position utilized.Hope you can undertand what I wrote..:-)
-
WSAndrewKKWalker
AskWoody LoungerOctober 28, 2009 at 3:30 pm #1183506🙂 No worries. The header table has: a one to many relationship to the detail table. Fields: (key-no duplicates)-BillNo, PersonID,InvDate,year, cycle
subordinate table to Header: AcctAssets has fields: (key-no duplicate)-AcctNo,BillNo,GroupID,AcctInfo,Amt, Notes.
I would like the query to get the personID and provide how many AcctNo records under that BillNo before appending the datas to the table.
Third table is subordinate to AcctAssets and will need the same as the previous table: HoursOnJob has fields: (key-no duplicate)-SubAcctNo, AcctNo, BillNo, position, abbr, hours, rate, Amt.
So in theory:
-Header will have one row of a BillNo with the main total of all subordinates.
-AcctAssets will have how many accts (AcctNo) the BillNo used with their respective totals.
-HoursOnJob will then break it down by SubAcctNo used in AcctNo on a BillNo with hours and position utilized.Hope you can undertand what I wrote..:-)
Not quite sure why you would want to append anything.
If all the data already exists in the relevant tables, you ought to be able to extract relevant data out using a Grouping query.
Reckon it will be easier to see an actual example with expected output, because I suspect there is a better solution other than appending. -
WSLastcall
AskWoody LoungerNovember 5, 2009 at 12:51 pm #1184366Not quite sure why you would want to append anything.
If all the data already exists in the relevant tables, you ought to be able to extract relevant data out using a Grouping query.
Reckon it will be easier to see an actual example with expected output, because I suspect there is a better solution other than appending.Here is a sample of database and two images of what I am trying to do automated.Thanks for all your help.
-
WSHansV
AskWoody LoungerNovember 5, 2009 at 2:23 pm #1184375The thread Item Number (2003) should give you some ideas.
-
WSLastcall
AskWoody LoungerNovember 6, 2009 at 9:15 am #1184504The thread Item Number (2003) should give you some ideas.
HansV, thanks for the thread, I got the code below to add the number to the first record but is not looping to the next record in the subform. Any ideas?
Private Sub Form_Load()
Me.VCHR_LN_NO = Nz(DMax(“VCHR_LN_NO”, “VCHR_LN”, “AutoID =” & Me.AutoID), 0) + 1
End Sub
-
WSHansV
AskWoody Lounger -
WSLastcall
AskWoody LoungerNovember 6, 2009 at 3:30 pm #1184559The code should not be in the On Load event of the form. Please read the thread I pointed to again.
I read the whole thread, if I use the before update or On load event the code changes the field value Accordantly. I am trying to make the code loop thru the selected records in the subform and change the field values, to reflect a sequencial order. I placed the code in the On current event and it changes the first record in the required field to “1”, but is no changing the other records field value; I want the code to change the next records as well.
If I select the next record on the subform, the code executes and changes the next record field value to “2” because of the On current event..which is perfect..:-); I am trying to emulate that process automatic with a Do while loop statement but is not working.
Private Sub Form_Current()
Do
Do While (Me.VCHR_LN_NO) = 0
Me.VCHR_LN_NO = Nz(DMax(“VCHR_LN_NO”, “VCHR_LN”, “AutoID =” & Me.AutoID), 0) + 1Exit Do
LoopLoop Until (Me.VCHR_LN_NO) 0
Exit Sub
End Sub
-
WSHansV
AskWoody LoungerNovember 6, 2009 at 4:27 pm #1184569 -
WSLastcall
AskWoody LoungerNovember 18, 2009 at 8:41 am #1185866You should NOT do it this way. The Link Master Fields and Link Child Fields properties of each subform should be set so that the appropriate field will be filled in automatically, and code in the Before Insert of Before Update event to fill in the sequence number.
HansV, I have being trying to get this done but cant see to find the solution. I came up with the below event procedures to change all records in the field in a sequencial order.The field default value is “0” when it gets created from the queries and added into the table that keep the data with required field format and information. By doing this, I only can change 3 records automatically to show a sequence of (1,2,3)in the field.
Private Sub Form_Current()
If (Me.SUB_LN_NO) = 0 Then
Me.SUB_LN_NO = Nz(DMax(“SUB_LN_NO”, “VCHR_LAB_VEND”, “REF1_ID =” & Me.REF1_ID), 0) + 1
End IfEnd Sub
Private Sub Form_AfterUpdate()
RunCommand acCmdRecordsGoToNext
If (Me.SUB_LN_NO) = 0 Then
Me.SUB_LN_NO = Nz(DMax(“SUB_LN_NO”, “VCHR_LAB_VEND”, “REF1_ID =” & Me.REF1_ID), 0) + 1
End IfEnd Sub
Private Sub Form_AfterInsert()
RunCommand acCmdRecordsGoToNext
If (Me.SUB_LN_NO) = 0 Then
Me.SUB_LN_NO = Nz(DMax(“SUB_LN_NO”, “VCHR_LAB_VEND”, “REF1_ID =” & Me.REF1_ID), 0) + 1
End IfEnd Sub
I was trying to create a loop to do this for me and if I have more than 3 records to change; but is not working for some reason.
Dim dbs As DAO.Database
Dim rs As DAO.RecordsetSet dbs = CurrentDb
Set rs = dbs.OpenRecordset(“VCHR_LAB_VEND”, dbOpenDynaset)Do While Not rs.EOF
If (Me.SUB_LN_NO) = 0 Then
Me.SUB_LN_NO = Nz(DMax(“SUB_LN_NO”, “VCHR_LAB_VEND”, “REF1_ID =” & Me.REF1_ID), 0) + 1
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set dbs = Nothing -
WSHansV
AskWoody Lounger -
WSLastcall
AskWoody LoungerNovember 24, 2009 at 10:22 am #1186586I am very sorry; I’m not able to get my point across. I hope that someone else will be able to help you.
No worries, HansV!! I know i am not getting my point across; I was able to emulate the thread you suggested. It creates the sequence as new files are created, not when the files are already existing in the table. You’re still the greatest guru…:-)
-
WSHansV
AskWoody Lounger -
WSAndrewKKWalker
AskWoody LoungerNovember 24, 2009 at 12:26 pm #1186616Pictures are good, but when should the sequencing be done,
and in what order.Is it when a parent changes or a child.
Is it when a New child record is added, OR after a change.All pretty relevant details.
However you write the sequence numbers against the child records, the sequence will be based
upon the order that the rows are retrieved from the child recordset.Also even if looping, what would be the key field that links parent to child, OR
are there 2 key fields etc.None of that is obvious from your pictures.
You just need to explain how the sequence relates from parent to child,
and what the relevant triggers are. -
WSAndrewKKWalker
AskWoody LoungerOctober 28, 2009 at 3:31 pm #1183507It’s like 25 or 6 to 4…
Funny you should mention that, a few weeks ago I converted ’Transit Authority’ from Vinyl to MP3.
-
-
-
-
WSLastcall
AskWoody LoungerNovember 24, 2009 at 2:36 pm #1186665You shouldn’t use form code to add sequence numbers to already existing records, but either create an update query to fill in the field, or write code that loops through the records in the appropriate table(s) and updates the records.
Pictures are good, but when should the sequencing be done,
and in what order.Is it when a parent changes or a child.
Is it when a New child record is added, OR after a change.All pretty relevant details.
However you write the sequence numbers against the child records, the sequence will be based
upon the order that the rows are retrieved from the child recordset.Also even if looping, what would be the key field that links parent to child, OR
are there 2 key fields etc.None of that is obvious from your pictures.
You just need to explain how the sequence relates from parent to child,
and what the relevant triggers are.Hey, guys! I really appreciate all ya do…thanks..:-)
Dont know if ya were able to open the database sample that I posted with the images. but it does make sense to create an update query to create the senquency by unique master and child id records. If you get a change to open the database sample; the records in tables VCHR_HDR, VCHR_LN and VCHR_LAB_VEND are inserted by the respective append queries (appVCHR_HDR, etc). The Form frmExport will retrieve the data according to the date criterias; when this data is uploading it has to be already in the sequencial order by their respective ID. The master and child link for the first and second sub form is the autoID field; the second and third sub form are link thru the REF1_ID field. The fields that I’m trying to create the sequence are not primary keys or used as link fields; i just need to be able to create the sequence in accordance with the previous mention linking fields.
In the main form I have a button that executes the append queries to create the data for the tables mentioned previously; then the subforms as they load are retrieving the data from the tables according to their parent to child link. So, my problem or what I am trying to achieve is, as they doing that or before the data is fully display. I want to sequence these two fields on each second and third subforms as you see in the images posted. Hope this help..Thank again guys!!
-
WSAndrewKKWalker
AskWoody LoungerNovember 24, 2009 at 3:28 pm #1186681Hey, guys! I really appreciate all ya do…thanks..:-)
Dont know if ya were able to open the database sample that I posted with the images. but it does make sense to create an update query to create the senquency by unique master and child id records. If you get a change to open the database sample; the records in tables VCHR_HDR, VCHR_LN and VCHR_LAB_VEND are inserted by the respective append queries (appVCHR_HDR, etc). The Form frmExport will retrieve the data according to the date criterias; when this data is uploading it has to be already in the sequencial order by their respective ID. The master and child link for the first and second sub form is the autoID field; the second and third sub form are link thru the REF1_ID field. The fields that I’m trying to create the sequence are not primary keys or used as link fields; i just need to be able to create the sequence in accordance with the previous mention linking fields.
In the main form I have a button that executes the append queries to create the data for the tables mentioned previously; then the subforms as they load are retrieving the data from the tables according to their parent to child link. So, my problem or what I am trying to achieve is, as they doing that or before the data is fully display. I want to sequence these two fields on each second and third subforms as you see in the images posted. Hope this help..Thank again guys!!
Hadn’t got the database then, but have now.
So best idea would probably be to have code behind the parent load button,
that builds all the sequences into the child tables,
before they are loaded when the export button is clicked.
Then at the end of that process instruct access to load the subforms rather than getting them loaded twice and then having to requery them.
I’ll have a look. -
WSAndrewKKWalker
AskWoody LoungerNovember 24, 2009 at 5:37 pm #1186710I’ll have a look.
Had look, but it’s pretty bust.
The subforms and the combo’s reference the fields on the main form, which seem to reference the fields on the subforms.
It errors with a parameter as soon as it is loaded.
So half the combos never get populated.
Also Access loads subform data before it loads the main form data.Final point, it is not clear in each temporary table, which field you are trying to sequence,
I have some code that does some sequencing against the button press, by looping through the tables.
This is shown below.
But I really an not quite sure how and what you are trying to update and when.
You need to give a step by step process required, because its a bit confused.Also, a lot of the stuff on the forms does not appear to work.
Anyway
Example Loop that might well be of no use at all
Code:Private Sub cmdCreateHeader_Click() Dim rstHdr As DAO.Recordset, strSQLH As String Dim rstLN As DAO.Recordset, strSQLLN As String Dim rstLAB As DAO.Recordset, strSQLLAB As String Dim lngSEQLN As Long, lngSEQLAB As Long lngSEQLN = 0 lngSEQLAB = 0 DoCmd.SetWarnings False ‘Build the Data for the Subforms these don’t work at the moment because ‘the combo boxes don’t work correctly at the top, but if they did…. ‘DoCmd.OpenQuery “appVCHR_HDR” ‘DoCmd.OpenQuery “appVCHR_LN” ‘DoCmd.OpenQuery “appVCHR_LAB” ‘Now Run Updates to the Sequencing strSQLH = “Select AutoID From VCHR_HDR” Set rstHdr = CurrentDb.OpenRecordset(strSQLH) Do Until rstHdr.EOF ‘Now Loop Through the LN Table strSQLLN = “SELECT * FROM VCHR_LN WHERE AutoID=” & rstHdr!AutoID Set rstLN = CurrentDb.OpenRecordset(strSQLLN) lngSEQLN = 0 Do Until rstLN.EOF lngSEQLN = lngSEQLN + 1 rstLN.Edit rstLN!VCHR_LN_NO = lngSEQLN rstLN.Update ‘Now Get the Data for the LAB strSQLLAB = “SELECT * FROM VCHR_LAB_VEND WHERE REF1_ID=” & rstLN!REF1_ID Set rstLAB = CurrentDb.OpenRecordset(strSQLLAB) lngSEQLAB = 0 Do Until rstLAB.EOF lngSEQLAB = lngSEQLAB + 1 rstLAB.Edit rstLAB!VCHR_LN_NO = lngSEQLN rstLAB!SUB_LN_NO = lngSEQLAB rstLAB.Update rstLAB.MoveNext Loop rstLN.MoveNext Loop rstHdr.MoveNext Loop rstLAB.Close rstLN.Close rstHdr.Close Set rstLAB = Nothing Set rstLN = Nothing Set rstHdr = Nothing Me!qryExport.Requery Me!qryExport.Form![qryVCHR_LN subform].Requery ‘This last line may well not work it should in principle but it failed for me Forms!frmExport![qryExport].Form![qryVCHR_LN subform].Form![qryVCHR_LAB subform].Requery DoCmd.SetWarnings True
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
57 minutes ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
59 minutes ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
56 minutes ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
1 hour, 48 minutes ago -
re-install Windows Security
by
CWBillow
4 hours, 13 minutes ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
7 hours, 54 minutes ago -
macOS Tahoe 26
by
Alex5723
2 hours, 7 minutes ago -
Migrating from win10 to win11, instructions coming?
by
astro46
9 hours, 7 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
8 hours, 41 minutes ago -
Recommended watching : Mountainhead movie
by
Alex5723
21 hours, 26 minutes ago -
End of support for Windows 10
by
Old enough to know better
6 hours, 48 minutes ago -
What goes on inside an LLM
by
Michael Covington
5 hours, 52 minutes ago -
The risk of remote access
by
Susan Bradley
31 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
18 hours, 5 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
23 hours, 40 minutes ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
1 day, 6 hours ago -
EaseUS Partition Master free 19.6
by
Alex5723
6 hours, 55 minutes ago -
Microsoft : Edge is better than Chrome
by
Alex5723
1 day, 19 hours ago -
The EU launched DNS4EU
by
Alex5723
2 days, 8 hours ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
1 day, 22 hours ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
2 days, 13 hours ago -
Set default size for pasted photo to word
by
Cyn
2 days, 19 hours ago -
Dedoimedo tries 24H2…
by
Cybertooth
2 days, 7 hours ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
3 days, 18 hours ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
1 day, 11 hours ago -
Small desktops
by
Susan Bradley
12 hours, 13 minutes ago -
Totally disable Bitlocker
by
CWBillow
2 days, 12 hours ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
3 days, 16 hours ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
4 days, 22 hours ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
2 days, 17 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.