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 2801
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,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).
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,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.
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,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 : - 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,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.
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.
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 :-)
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.
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...
|
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...
|
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?.....
|
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...
|
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...
| |
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...
|
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 ...
|
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
...
|
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...
|
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. ...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |