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.
11 2823
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: - Me = IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
-
[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.
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).
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... =/
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.
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: - Me = iff(Len([Reports]![MainReport]![SubReport1]![SubReport2]![CountField] >= 2), _
-
iff(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 11 _
-
Or Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 12 _
-
Or Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 2) = 13, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "th")))), _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 1, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "st", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 2, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "nd", _
-
IIf(Right([Reports]![MainReport]![SubReport1]![SubReport2]![CountField], 1) = 3, _
-
[Reports]![MainReport]![SubReport1]![SubReport2]![CountField] & "rd", _
-
[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...
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 : - Dim strOrd As String
-
Dim lngCard As Long
-
-
lngCard = Reports!MainReport!SubReport1!SubReport2.CountField
-
strOrd = lngCard & IIf(((lngCard Mod 100) > 10) And _
-
((lngCard Mod 100) < 14), "th", _
-
Choose(lngCard Mod 10 + 1, _
-
"th","st","nd","rd","th","th","th","th","th","th"))
*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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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),
|
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.
|
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
|
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
| |
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 ,
|
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
|
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
|
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.
|
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: ...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| | |