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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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, 7 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 #1183506No 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
-
Chrome ‘Scream to Unlock’ : Scream louder to get more time on Social Media
by
Alex5723
59 minutes ago -
Taskbar icon size
by
CWBillow
4 hours, 52 minutes ago -
Is it Local or is it Microsoft Account?
by
RetiredGeek
17 minutes ago -
Does Your State Reveal Who’s Been Hacked?
by
Nibbled To Death By Ducks
20 hours, 28 minutes ago -
A one-year extension to Windows 10 — almost free!
by
Susan Bradley
1 hour, 35 minutes ago -
Windows Configuration Update (KB5062324) – June 2025
by
Alex5723
7 hours, 51 minutes ago -
A federal judge sides with Anthropic in lawsuit over training AI
by
Alex5723
1 day, 1 hour ago -
Name of MS Word Formatting Feature
by
John Baum
14 hours, 9 minutes ago -
InControl Failure?
by
Casey H
12 hours, 31 minutes ago -
Microsoft : Free 1 year support for Windows 10 after EOL
by
Alex5723
14 hours, 13 minutes ago -
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
5 hours, 57 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
2 days ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
1 day, 19 hours ago -
Is your device eligible?
by
Susan Bradley
2 days, 3 hours ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
2 days, 9 hours ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
2 days, 9 hours ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
2 days, 10 hours ago -
New Canon Printer Wants Data Sent
by
Win7and10
2 days, 11 hours ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
22 minutes ago -
AI is for everyone
by
Peter Deegan
2 days, 10 hours ago -
Terabyte update 2025
by
Will Fastie
2 days, 4 hours ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
11 hours, 58 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
1 day, 5 hours ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
1 day, 13 hours ago -
Plugged in 24-7
by
CWBillow
2 days, 19 hours ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
3 days, 23 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
3 days, 20 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
5 days, 14 hours ago -
Are Macs immune?
by
Susan Bradley
8 hours, 16 minutes ago -
HP Envy and the Function keys
by
CWBillow
4 days, 21 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.