473,385 Members | 1,370 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,385 software developers and data experts.

Update Sequentially a field based upon the occurence of another field

1
My table has 2 fields VIN & Sequence. The VIN field has data as follows:

VIN Sequence
123
123
123
234
234
345
456

I would like to write an update query so that the Sequence field results is as follows:

VIN Sequence
123 1
123 2
123 3
234 1
234 2
345 1
456 2

So to summarize every time the VIN changes Sequence goes back to 1. If VIN has multiple same entries the sequence is incremented by 1.

Thanks

[z{Moderator's comment: This post is the result of the member posting the same question in three different threads using two names.}]
Feb 28 '13 #1
5 1389
zmbd
5,501 Expert Mod 4TB
Unless you have a unique/primary key that you did not provide, or some other method of ordering, neither a simple update query nor a simple VBA solution is available from what I've seen and done and the results would be somewhat arbitrary.
Feb 28 '13 #2
zmbd
5,501 Expert Mod 4TB
PDOIZ/PDOI:
1) The use of two different Avatar names is normally prohibited.

2) Do not double post your questions. Please refer to the Site FAQ and forum stickies.


[EDIT]
3) If you thought the double posting was bad... I just merged the third!
Feb 28 '13 #3
ADezii
8,834 Expert 8TB
Assuming your Table Name is Table1 and that the [VIN] Field cannot be NULL (Required = Yes), then there is a relatively simple solution using VBA:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim MyDB As DAO.Database
  3. Dim rs1 As DAO.Recordset
  4. Dim rs2 As DAO.Recordset
  5. Dim intCtr As Integer
  6.  
  7. strSQL = "SELECT DISTINCT Table1.VIN FROM Table1 ORDER BY Table1.VIN;"
  8.  
  9. Set MyDB = CurrentDb
  10.  
  11. 'Generate a Recordset of Unique VIN Numbers sorted Ascending
  12. Set rs1 = MyDB.OpenRecordset(strSQL, dbOpenSnapshot, dbOpenForwardOnly)
  13.  
  14. Do While Not rs1.EOF
  15.   'All Records belonging to each Unique VIN Number
  16.   Set rs2 = MyDB.OpenRecordset("SELECT * FROM Table1 WHERE [VIN] = " & rs1![VIN], dbOpenDynaset)
  17.     Do While Not rs2.EOF
  18.      intCtr = intCtr + 1    'Increment Sequence Counter for each Unique VIN
  19.       rs2.Edit
  20.         rs2![Sequence] = intCtr
  21.       rs2.Update
  22.         rs2.MoveNext
  23.     Loop
  24.       intCtr = 0        'RESET Sequence Counter for each Unique VIN
  25.       rs1.MoveNext      'Next Unique VIN
  26. Loop
  27.  
  28. rs1.Close
  29. rs2.Close
  30. Set rs1 = Nothing
  31. Set rs2 = Nothing
Feb 28 '13 #4
zmbd
5,501 Expert Mod 4TB
ADezii:
Certainly one solution; however, are we not assuming that the order given is indeed the correct order for inserting the sequetial count? As such, it why I didn't offer any solution until we found out about a primary key or other method of ordering the records.
Feb 28 '13 #5
zmbd
5,501 Expert Mod 4TB
ADezii:
Sorry there A:
Appears that Mr.P has several user names and posted the same question multiple times!
Feb 28 '13 #6

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

Similar topics

5
by: j_liu21 | last post by:
Is something like this possible? A form with x fields named field1, field2, ... fieldx I'd like to set the field specified in the parameter function SetUnknownField(FieldID) {...
3
by: Dave [Hawk-Systems] | last post by:
Have a table with fnumber and number, both text fnumber is a phone number, format "8005551212" number needs to be the same number but in the format "(800) 555-1212" we currently run the...
5
by: Randy A. Bohannon | last post by:
I have two fields on a form: GPA and Points. GPA will be entered by the user. I would like Points to be filled automatically depending on the value of GPA. For example, the following code...
1
by: Alienz | last post by:
I'm sure this is easy so if you have a sec pls help me out thx. Let say I have an inventory table and at the end of the month I want to move the info in 1 field (total end of month 1) into...
3
by: euphorica | last post by:
I am making an inventory database. I have a field InventoryNumber where I put a specific code. The code always starts with a particular letter. I would like to fill in another field with...
4
by: rcwoodard | last post by:
Hello all. I have a continuous form that I need to make a field invisible or visible depending on the selection in another field. I have tried using Form_Current() and the following code: ...
2
by: ACF | last post by:
Hello, I'm having two memo fields beside each other for translating purposes. When I scroll down the text in Memo 1 to see what I want to translate, then move to Memo 2 to actually translate the...
1
by: mrobinsc | last post by:
** This SQL statement returns 4 rows SELECT COUNT(*) G.ACTIVITY_ID G.RESOURCE_TYPE G.RESOURCE_CATEGORY G.RESOURCE_SUB_CAT G.ANALYSIS_TYPE G.PROJECT_ID
1
by: sd_eds | last post by:
I have two fields, "Item" and "Information" in the same table. "Information" contains three items from a seperate table created by a lookup. I would like to substring out the first item and place...
3
by: David Snyder | last post by:
I have a date that is used to show when someone completed a task and the task is due again in 12,24,48 months. I am trying to update a field for the next due date. Of course after I get this done, I...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.