A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

numbering rows



 
 
Thread Tools Display Modes
  #1  
Old July 7th, 2009, 02:07 PM posted to microsoft.public.access
florin
external usenet poster
 
Posts: 25
Default 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  
Old July 7th, 2009, 03:38 PM posted to microsoft.public.access
Arvin Meyer MVP
external usenet poster
 
Posts: 640
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.