Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This is killing me I know there is 2

Status
Not open for further replies.

sccofer

Programmer
Feb 4, 2002
8
US
This is killing me I know there is an elegant solution but I can't
figure it out. I have a simple query which gives me the following
results...

File Cost Center
1 2x2
1 3ee
1 1xc
2 1qw
2 2x2
3 1a1

I am trying to add a thrid column that will give me a sequential count of the number of cost centers associated with each unique file number. For the above example the result would be...

File Cost Center Result
1 2x2 1
1 3ee 2
1 1xc 3
2 1qw 1
2 2x2 2
3 1a1 1

I can get a total count for each file using DCOUNT but I am finding it is impossible to get a sequential count. I have been through the newsgroups and can't find a simple solution. This can't be that hard can it??? Any help anyone could offer would be most appreciated.
Thanks in advance.

Scott
 
Hmm, tricky one... It's easy to do at report level - just check out the runningsum function in help - but query level is another matter altogether...
 
This should be simple.

Add a group header to your report for the File field. Set this header's visible property to No.

Add a text box to the detail section to display the running count. Set its control source to =1 and its Running Sum property to Over Group. This value will reset for each group.

That should do it.....
 
Paste this code into a new Module -

Global glngFileNo as Long
Global glngSequence as Long

Public Function GetSequence(FileNo as Long) as Long

If glngFileNo = FileNo Then
glngSequence = glngSequence + 1
Else
glngSequence = 1
End If

GetSequence = glngSequence

End Function

Then, for the Sequence column in your query, put -
Sequence: GetSequence([FileNo])
 
Error in last one.

After the else statement, you need to set the global file number to the current one, thus -

If glngFileNo = FileNo Then
glngSequence = glngSequence + 1
Else
glngSequence = 1
glngFileNo = FileNo
End If

Sorry about that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top