Click to See Complete Forum and Search --> : Change CR Field Value From VB6
JerseyKid
Mar 8th, 2006, 06:43 AM
I have created a report and am looking to change a value of one of the fields through VB6...can this be done?
I was looking to do something like this (I know this is wrong but something along these lines) the field in CR is called for example: USERID
Report.Field.USERID = "WhateverValue"
I know this is wrong but do you get what I mean? If not please ask and I will try and explain in more depth... If it can be done what would the code be?
Thanks
brucevde
Mar 8th, 2006, 09:58 AM
Which Version, Edition and Licensing of CR do you have? What type of object is the UserId field? Database, Textbox, Formula, Special Field?
JerseyKid
Mar 9th, 2006, 02:38 AM
I am using version 9 of CR
UserID is a Textbox
GaryMazzone
Mar 9th, 2006, 07:29 AM
You would probably want to use a Parameter field in the report. That way you can set the parameter value from VB when you process the report.
brucevde
Mar 9th, 2006, 12:34 PM
All report objects can be accessed via VB if you have a developer edition. Add a refererence to the Crystal Reports ActiveX Designer Runtime Library to your project.
This VB6 code is for Crystal 8.5 but it should be similar for version 9.
Dim objCrystal As New CRAXDRT.Application
Dim objReport as CRAXDRT.Report
Dim objTextBox as CRAXDRT.TextObject
Set objReport = objCrystal.OpenReport(ReportPath, 0)
Set objTextBox = objReport.Sections("Section1").ReportObjects("Text6")
objTextBox.SetText "User Id"
'code to view/print report
You will need to find the correct Section name and TextObject name used by Crystal.
JerseyKid
Mar 10th, 2006, 05:28 AM
Could you explain what is entered into the ("Section1") part?
I am a little confused?!
sacramento
Apr 1st, 2008, 12:26 PM
Hi Brucevde:
Do you know the way to change a name field create in a .ttx file?
It's the same way that you present in your post?
Thanks
brucevde
Apr 1st, 2008, 12:44 PM
Sorry, I am not sure exactly what you are asking.
Assume the .ttx file contains
Id Long
CustomerName String 30
Are you asking how to change the above ttx file to something like the following and then update the report file (.rpt) to change all occurrances of Id to CustomerId.
CustomerId Long
CustomerName String 30
sacramento
Apr 1st, 2008, 12:54 PM
yes thats it
VBFnewcomer
Apr 2nd, 2008, 04:03 AM
Could you explain what is entered into the ("Section1") part?
Bruce's code can also be written like this
Report.Sections(1).ReportObjects(1).SetText "YOUR TEXT"
Where
.Sections(1) is the section (Report Header, Page Header, Details etc) where the Textbox resides
.ReportObjects(1) is item number of the object (within the section) you want to manipulate. In present case Textbox
sacramento
Apr 2nd, 2008, 06:05 PM
Hi:
Thanks for your answear,but I have a few doubts:
1 - The code you present is valid for Text box create in CR right?Wich way I can see the number of the object?
When you tell that .Sections(1) is the section (Report Header, Page Header, Details etc),I presume if the section is details than .sections(3)...thats it?
2 - And for database fields?It's the same sintax?Because I want rename a database field in my report before sort a recordset
Thanks
VBFnewcomer
Apr 3rd, 2008, 12:11 AM
When you tell that .Sections(1) is the section (Report Header, Page Header, Details etc),I presume if the section is details than .sections(3)...thats it? Not necessarily.. You might have seen using the Section Expert you can insert more sections
sacramento
Apr 3rd, 2008, 03:16 AM
Ok...That's correct about .Sections(x)
I had try the code and work with text box...But with the database fields not work...do you know the syntax for those fields?
VBFnewcomer
Apr 3rd, 2008, 04:03 AM
you want to rename a dbfield in report? what do you gain by that...
If absolutely necessary I would recommend you create view/Query with the desired field names and link it to the report instead.
sacramento
Apr 3rd, 2008, 06:59 AM
I work with .ttx files,and I don't have any link with database...My problem is that I had create a field(in .ttx file) named "Registo",but I need chance this name sometimes for "RegistoCM" other times to "RegistoDE"...If I do not chance the name I can't see the records in my report...That's because I need chance the name in this field...
VBFnewcomer
Apr 3rd, 2008, 07:03 AM
I don't have any knowledge of these .ttx files. Anyway try renaming by the above methods and let us know the results. Remember each field placed in the report is an item withing the section...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.