By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,705 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,705 IT Pros & Developers. It's quick & easy.

Record counter in Access

P: n/a
Sam
Is there a formula or easy way to add a record counter in Access to a
query?

I have a field that contains a file number this file. I want to add a
counter like below.
Field Name Field Name (B)
FileNumber ElCounter
9565845 1
9565845 2

9552456 1
9552456 2
9552456 3
5695695 1
5695695 2
5695695 3
5695695 4
5695695 5
Thanks for your assistance.
Sam
Oct 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Sam" <sa********@comcast.netwrote in message
news:e4**********************************@p49g2000 hsd.googlegroups.com...
Is there a formula or easy way to add a record counter in Access to a
query?

I have a field that contains a file number this file. I want to add a
counter like below.
Field Name Field Name (B)
FileNumber ElCounter
9565845 1
9565845 2

9552456 1
9552456 2
9552456 3
5695695 1
5695695 2
5695695 3
5695695 4
5695695 5
Thanks for your assistance.
Sam
Try a public function that counts up and resets to 0 when the FileNumber
changes.
You may need to call CountUp(Null) before opening your query

ELCount: CountUp([FileNumber])

Un-tested Code

Public Function CountUp(FileNumber as variant) as Integer
Static iCount as Integer
Static LastFileNumber as variant

if LastFileNumber <FileNumber then
iCount = 0
LastFileNumber = FileNumber
endif
iCount = iCount + 1
CountUp = iCount
EndFunction
Oct 2 '08 #2

P: n/a
Sam wrote:
Is there a formula or easy way to add a record counter in Access to a
query?

I have a field that contains a file number this file. I want to add a
counter like below.
Field Name Field Name (B)
FileNumber ElCounter
9565845 1
9565845 2

9552456 1
9552456 2
9552456 3
5695695 1
5695695 2
5695695 3
5695695 4
5695695 5
Thanks for your assistance.
Sam
Well, if you had an autonumber it would be easy to do.
Dcount("*","TableName","AutoNumFldName < " & [AutoNumFldName] & _
" And FileNumber = " & [FileNumber]) + 1

Oct 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.