If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
numbering rows
I have a table with fields:
Nrcrt Field 2 Field 3 F 40 F 40 F 50 F 50 F 50 and I want fill field "Nrcrt" (numbering rows depending on Field3) : Nrcrt Field 2 Field 3 1 F 40 2 F 40 1 F 50 2 F 50 3 F 50 How could I do that? Thanks |
#2
|
|||
|
|||
numbering rows
I used a variable (varLast) to hold the Field3 value was from the previous
record If the current record is the same, then just increment the counter, otherwise reset it to 1 and hold the new value. Create a new sub in a form, and just call it by name. The code is untested so try it on a copy first. Dim db as DAO.Database Dim rst as DAO.Recordset Dim intCount as Integer Dim varLast as Variant Set db = CurrentDb Set rst = db.OpenRecordset( "SELECT Field3, Nrcrt FROM MyTable ORDER BY Field3") With rst Do Until .EOF If !Field3 = varLast Then intCount = intCount + 1 Else intCount = 1 varLast = !Field3 End If .Edit !Nrcrt = intCount .Update .MoveNext Loop End With Exit_He rst.Close Set rst = Nothing Set db = Nothing -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Florin" wrote in message ... I have a table with fields: Nrcrt Field 2 Field 3 F 40 F 40 F 50 F 50 F 50 and I want fill field "Nrcrt" (numbering rows depending on Field3) : Nrcrt Field 2 Field 3 1 F 40 2 F 40 1 F 50 2 F 50 3 F 50 How could I do that? Thanks |
Thread Tools | |
Display Modes | |
|
|