473,651 Members | 2,987 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 2823
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,568 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,568 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,568 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,568 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

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

Similar topics

1
1227
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 report on that query, so when the manager runs the report they can "type" in the user's ID (but there is no error checking, thus the desire for a list). I have a UserId table with each employee and UserId listed that I would like to be able to...
12
10383
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 @salesdate as varchar(20),
2
12463
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?.. in other words I want to change it's Format: Horizontal Alignment from Left To Right if the data passed in is an Integer, Currency, or DateTime.
0
2125
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 ReportDocument rpt.Load(Server.MapPath("rptPurchaseOrder.rpt")) rpt.SetDataSource(dsPOData) Me.CRViewer.ReportSource = rpt
1
1156
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 bottom for the closed ones and having a separate query for the open and closed records. I'm running into numerous problems such as page-breaks, forcing new page, etc. Any better ideas, I'm certain there are! Thanks! Brian
1
6778
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 "SchIssueDate" is Date format. I am trying to create a S-Curve for the documents to be issued each month to show the required progress. I have made this query for this: SELECT Format(,"mmm-yyyy") AS ,
1
4330
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 1111 100 1121 100 1131 200 1111
0
2742
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 AppReports Reports *.rpt
3
1803
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 others. If I am able to take the current login name into a variable, this can be managed. But how to take logged-in-username of that particular user for running a report when the system is being accessed by many users parallely.
0
878
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. The published report itself runs fine when called through the Reporting Services Folder.aspx. It also runs fine if I run the web app on my own machine in VS. If I try to run the web app on the server and call the report, I get this error: ...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.