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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming a saved subreport. 1

Status
Not open for further replies.

tinka

Technical User
Apr 4, 2001
2
US
I created a report with 3 subreports in it. After publishing to the web I realized that one of my subreport names needed to be shortened to make it look better. I resaved that subreport as a new name. But it would not chnage it. I then saved it as totally new report deleted the old subreport and reimported the newly named report as a subreport. To my surprise after importing this new report it was still named the old ugly name I wanted to get rid of. Does anyone out there know what I am doing wrong? Or is there another way to change the name of a subreport?

Please help, I am going live with these reports in one week.

Thank You
 
Bad News.

Once an rpt has been inserted as a subreport it is internally branded with the name, and this name becomes a permanent mark. Even when saved externally and re-inserted. The only way to change it is to hex-edit the RPT file. Even then, the subreport name is encrypted, although it is a simple letter/number pattern. Who knows why.

The only other alternative is to re-create the subreport from scratch, and re-insert it. Ken Hamady
On-site custom Crystal Reports Training and Consulting.
Quick Reference Guide to using Crystal in VB.
 
What would that "simple" letter/number pattern be? I like the fact that the database name, user, and password are not encrypted but the subreport's name is. Seems backwards to me.
 
Disclaimer - the following is certainly not endorsed by Crystal Decisions and I can't take responsibility for you Hex-editing your RPT files. It is very easy to corrupt a file, or possibly worse.

That being said, here is the conversion table that I have worked out for upper and lower case letters. I am sure you could also figure out numbers and symbols. This should at least enable you to find your subreport name in the RPT and attempt changing it.

IMPORTANT - Make sure that you keep the same NUMBER characters in the subreport name (the same length). Otherwise CR won't be able to validate the modifed file.

Steps:
1) Save the subreport as an external RPT file.
2) Mentally convert your existing name into these equivalent codes so that you can find it in the file.
3) Open the RPT in the HexEditor and find the existing name (it is just after a relatively white space).
4) Replace some characters using (again) the appropriate equivalent characters from the 3rd column.
5) Save the file
6) Re-Insert the subreport, and it should show the new name.

Name True Subreport
Char Ascii Equivalent (I think)
A 41 25
B 42 26
C 43 27
D 44 20
E 45 21
F 46 22
G 47 23
H 48 2C
I 49 2d
J 4a 2e
K 4b 2f
L 4c 28
M 4d 29
N 4e 2a
O 4f 2b
P 50 34
Q 51 35
R 52 36
S 53 37
T 54 30
U 55 31
V 56 32
W 57 33
X 58 3c
Y 59 3d
Z 5A 3e
a 61 05
b 62 06
c 63 07
d 64 00
e 65 01
f 66 02
g 67 03
h 68 0c
i 69 0d
j 6a 0e
k 6b 0f
l 6c 08
m 6d 09
n 6e 0a
o 6f 0b
p 70 14
q 71 15
r 72 16
s 73 17
t 74 10
u 75 11
v 76 12
w 77 13
x 78 1c
y 79 1d
z 7a 1e
Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
That hex editing was clever, but I think it is potentially very dangerous as you might destroy your rpt file.

It would be easier to use VB to change the name as follows.

dim Appn As craxdrt.Application
dim cReport As craxdrt.Report
Dim crSection As craxdrt.Section
dim crObject as object
Dim crSubReport As craxdrt.SubreportObject

Set Appn = CreateObject("CrystalRunTime.Application")
Set cReport = Appn.OpenReport("c:\folder\myreport.rpt")

For Each crSection In cReport.Sections
For Each crObject In crSection.ReportObjects
If crObject.Kind = crSubreportObject Then
Set crSubReport = crObject
If sOldName = crSubReport.SubreportName Then
crSubReport.SubreportName = sNewName
End If
End If
Next crObject
Next crSection

Send the report to a viewer or save on disk as CR8 rpt.
The new report has different subreport names.
Editor and Publisher of Crystal Clear
 
Of course the simplest would be to keep a copy of the subreport that hasn't been inserted. This can be renamed and inserted with it's new name as many times as needed.

ChelseaTech,

Does the suReportName command change the actual RPT? How do you do that last 'save on disk' step from VB. Are you exporting? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
The problem is that if you create a subreport inside your report, then "SAve Subreport as...", and bring it back in again, it appears with the same subreport name.

My VB code has a way to change the Subreportname property.

What happens after the code above is that I call a form with the CRViewer control and process the report. Then export it manually to another rpt file and the subreports appear with their new names.

Alternatively, export directly with
cReport.ExportOptions.FormatType = crEFTCrystalReport
cReport.ExportOptions.DestinationType = crEDTDiskFile
cReport.ExportOptions.DiskFileName = "C:\new.rpt"
cReport.Export False

I hope this helps.
Editor and Publisher of Crystal Clear
 
Nice to know there is a VB option. Maybe you should sell a VB utility to rename subreports for the non-programmers.

This 'feature' is one of the 2 reasons I teach my students to always create the subreport as a separate report, and then insert it as a subreport. The other reason is that if you accidentally place the subreport in the margin or on the ruler, you have to start over again from scratch.

Can you think of an advantage to creating the subreport within the main report? I haven't.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ok, I'll bite.

Ken, what other kinds of things can you change with this hex-edit thing???? LMC cryerlisa@hotmail.com

select * from Management where proj_mgmt_skills <> NULL

0 records returned
 
Lisa,

I haven't looked at anything else.

There is now a third party product listed on my links page (rptInspector) that allows you to change the name of a subreport, and sevearl other hidden properties. It also allows you to make batch changes to many reports at onec. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
rptInspector will not let you modify the subreport name for 8.5 reports.
You can not change the Report Path or Report File Name of a Sub-Report via .rpt Inspector because it's not exposed as a Read/Write property. You can change other properties of the sub-report including the Title.
 
I'm a non-programmer and dont't even have VB. Any suggestions as to how to get this going? Can I cut and past that text and give it to someone who has VB and have them compile it?
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim cr As New CRAXDDRT.Application
Dim rpt As CRAXDDRT.Report
Dim r2 As CRAXDDRT.Report
Dim sec As CRAXDDRT.Section
Dim sbr As CRAXDDRT.SubreportObject
Dim sFile As String
Dim sF1 As String
Dim sF2 As String
Dim sPath As String
Dim sTRGPath As String
Dim newName As String

sTRGPath = "C:\reports\"

sPath = "C:\dev source\gideons\reports\"

Me.OpenFileDialog1.Filter = "CRX|CNI*.rpt"
Me.OpenFileDialog1.InitialDirectory = sPath
Me.OpenFileDialog1.ShowDialog()
sF1 = Me.OpenFileDialog1.FileName
sF2 = sTRGPath & sF1.Substring(30)
newName = Me.OpenFileDialog1.FileName
newName = newName.Substring(42)
newName = newName.Substring(0, newName.Length - 4)
rpt = cr.NewReport()
rpt.PaperOrientation = CRAXDDRT.CRPaperOrientation.crLandscape

sbr = rpt.Sections(2).ImportSubreport(sF1, 0, 0)

sbr.SubreportName = newName
If Dir(sF2) <> "" Then Kill(sF2)
rpt.SaveAs(sF2, CRAXDDRT.CRReportFileFormat.cr80FileFormat)

MsgBox(sbr.SubreportName.ToString() & " " & sF2)

sbr = Nothing
sec = Nothing
rpt = Nothing
cr = Nothing



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top