473,503 Members | 4,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to put a running count on a report in the format of 1st, 2nd, 3rd etc

137 New Member
I'm trying to put a running count of the records related to the main record. I know you can set an unbound textbox with the Control Source of =1, and running sum of Over Group, however this only gives integers. What I'm after is adjusting it to display 1st, 2nd, 3rd, 4th etc instead.

Is there a way to do this? I thought about using VBA to do it but as the report opens in print preview it doesn't let you do anything after its loaded.

Thanks in advance.

Adam.
Jun 17 '11 #1
11 2801
Adam Tippelt
137 New Member
Aha, managed to solve this one by myself in the end. For anyone who's interested, I used an unbound textbox (CountField) to count the records Over Group. I then used a second unbound textbox that used a set of nested iif statements as the Control Source:

Expand|Select|Wrap|Line Numbers
  1. Me = IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
  2. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
  3. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
  4. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
  5. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
  6. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
  7. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th")))
This code will look at the texbox containing the record count (CountField), work out what the right most digit is, and apply the additional text accordingly. This then populates in the second textbox.

Hopefully this can help someone else as well, instead of it just looking like I'm talking to myself. :)

Adam.
Jun 17 '11 #2
NeoPa
32,557 Recognized Expert Moderator MVP
That's a fairly reliable way of finding the ordinal version of a number Adam (Watch out for 11 though).
Jun 17 '11 #3
Adam Tippelt
137 New Member
Ah, dammit. I even tried counting in my head looking for dodgy numbers!
I'll need to sort out 12 and 13 as well...cheers for the heads up... =/
Jun 17 '11 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I'm not going to post a link to another site but searching on "vba ordinal number" finds a few links which show how it can be done either with a formula or with VBA code.

Have fun.
Jun 17 '11 #5
Adam Tippelt
137 New Member
I couldn't see any links that offered any suitable suggestions to what I'm trying to achieve, though maybe it's just because it's a Friday afternoon.

I actually edited my original idea to incorporate 11th/12th/13th values, so it now looks like this:

Expand|Select|Wrap|Line Numbers
  1. Me = iff(Len([Reports]![MainReport]![SubReport1]![SubReport2]![CountField] >= 2), _
  2. iff(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 11 _
  3. Or Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 12 _
  4. Or Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 13, _
  5. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th", _
  6. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
  7. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
  8. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
  9. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
  10. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
  11. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
  12. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th")))), _
  13. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
  14. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
  15. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
  16. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
  17. IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
  18. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
  19. [Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th"))))
However this annoyingly has two problems:
1) It's 2091 characters long (or at least, my version is with correct report names put in), and the control source won't accept it because it's too long.
2) Putting it in a public function and referencing that as the control source also doesn't work, because the form opens in print preview and as it opens the report throws up run time error 2448 - you can't assign a value to this object.

Think I'd better investigate your search idea on Monday morning.
Why is nothing ever simple...
Jun 17 '11 #6
NeoPa
32,557 Recognized Expert Moderator MVP
That's some pretty strange looking VBA you have there Adam. I doubt it would ever run :-( (iff() doesn't exist and you can't assign a value to Me, etc)

Try this instead :
Expand|Select|Wrap|Line Numbers
  1. Dim strOrd As String
  2. Dim lngCard As Long
  3.  
  4. lngCard = Reports!MainReport!SubReport1!SubReport2.CountField
  5. strOrd = lngCard & IIf(((lngCard Mod 100) > 10) And _
  6.                        ((lngCard Mod 100) < 14), "th", _
  7.                        Choose(lngCard Mod 10 + 1, _
  8.                        "th","st","nd","rd","th","th","th","th","th","th"))
Jun 17 '11 #7
Adam Tippelt
137 New Member
*sigh* Friday night madness. The IFF was a typo, and should have been IIF.
And I was writing this in a blank VBA window on my database, so I temporarily added the "Me = " bit in to stop the VBA throwing up the "= expected" error everytime I navigated away from the code.
Aside from those obvious mistakes, the code does actually run correctly if you test it on a form. (The problem is that the code is too long for a record source, and the report won't let me run it from VBA)

Regarding your code, I don't understand which event in which I should put it - the main report's report_load? Or an event on subreport2?
Also should the strOrd variable be replaced with the name of the field I want populated with the answer?

I appreciate your help on this.

Adam.
Jun 20 '11 #8
NeoPa
32,557 Recognized Expert Moderator MVP
Adam Tippelt:
*sigh* Friday night madness. The IFF was a typo, and should have been IIF.
Exactly why we suggest you follow the stipulations in When Posting (VBA or SQL) Code ;-)

Actually, I was only suggesting replacement code for what you already had. If you were to ask I would suggest the Format event of whichever section the control is on (probably Detail in your case).
Adam Tippelt:
Also should the strOrd variable be replaced with the name of the field I want populated with the answer?
The name of the control, but essentially yes. I didn't have much of a context within which to work so I created one. If you're setting the value of a control then the strOrd part is superfluous.
Jun 20 '11 #9
Adam Tippelt
137 New Member
Exactly why we suggest you follow the stipulations in When Posting (VBA or SQL) Code ;-)
I never was good at following rules. ;)

Actually, I was only suggesting replacement code for what you already had. If you were to ask I would suggest the Format event of whichever section the control is on (probably Detail in your case).
Oh I didn't realise that - what I designed was originally to go in a control source (albeit 4 times too long...) so wasn't really sure where the VBA should go.

I put the code in Detail_Format - works like a charm!

Thank you yet again NeoPa! :)

Detail format certainly seems to be cropping up more and more often in answers to my questions, clearly I need to go away and learn what it has to offer.
Jun 20 '11 #10
NeoPa
32,557 Recognized Expert Moderator MVP
You're welcome Adam.

BTW You needn't think of them as rules if you're not comfortable with that idea. They're just common sense really (We just have rules because common sense is far less common than it should be). If members waste the experts time and efforts needlessly then the experts will understand the implication that their time is not appreciated. Which member, if they thought about it, would want to give that impression?
Adam:
Detail format certainly seems to be cropping up more and more often in answers to my questions, clearly I need to go away and learn what it has to offer.
That seems a very good idea. I expect you'll find it quite fascinating, some of what can be done :-)
Jun 20 '11 #11
Adam Tippelt
137 New Member
Yeah I meant it more of a joke than a serious answer. :)

I'd like to think I'm clear, even with the occasional typo!

common sense is far less common than it should be
You can certainly say that again...

Anyway, enough of me spamming this thread. Thanks again.
Jun 20 '11 #12

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

Similar topics

1
1223
by: MarkPtacek | last post by:
Objective: Have a manager select a user's ID from a list and have a report generated based on the user that is selected. Current Progress: I have created a run-time prompted query and based a...
12
10360
by: Bill Nguyen | last post by:
What's the VB syntax to run the CR report using the following SP? I use CrystalreportViewer and ReportDocument. Thanks Bill Here's the SP in SQLserver 2K: CREATE proc mysp_ReportSubmission...
2
12446
by: blackdevil1979 | last post by:
Hello, Is there a way to format the data when it is passed into the Crystal Report(CR).. for example.. In the original table, a number may be left aligned, how to change it to right alignment?.....
0
2115
by: Rabbit | last post by:
Dear All, I have recently using ASP.net 2.0 to build web application with Crystal Report for .net, one of my typical coding to generate report on web page as follows: Dim rpt As New...
1
1151
by: Parasyke | last post by:
Any ideas would help... I have a report for closed and opened orders. Open at top of page and closed at bottom. I could find no other way of accomplishing this other than having a sub-report at the...
1
6769
by: Vikas | last post by:
Hi all, I am working on a document control database where I have a table "tblControl" containing two columns "DocID" and "SchIssueDate". "DocID" is the key field with text format while...
1
4321
by: loki419 | last post by:
I have a simple select query that produces results similar to this LOCATION FUNCTION 001 1111 001 1111 100 1111 100 ...
0
2716
by: shanmukhi | last post by:
Hi All, i am very new to crystal reports.. how can i run crystal report(rpt file) from a jsp page.. i tried somthing by getting code from google my applicaction structure is like this ...
3
1794
by: mjkriab | last post by:
We have installed Oracle e-business suite. Now I have written a query for generating a report. I want to give some security to run this report by preventing the user from getting the details of...
0
872
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've never done this before. I have an ASP.Net 2.0 app running on an internal server (no special permissions, wide open access within our intranet.) I added a page with a report viewer control. ...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.