Change CR Field Value From VB6
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
Re: Change CR Field Value From VB6
Which Version, Edition and Licensing of CR do you have? What type of object is the UserId field? Database, Textbox, Formula, Special Field?
Re: Change CR Field Value From VB6
I am using version 9 of CR
UserID is a Textbox
Re: Change CR Field Value From VB6
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.
Re: Change CR Field Value From VB6
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.
VB Code:
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.
Re: Change CR Field Value From VB6
Could you explain what is entered into the ("Section1") part?
I am a little confused?!
Re: Change CR Field Value From VB6
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
Re: Change CR Field Value From VB6
Sorry, I am not sure exactly what you are asking.
Assume the .ttx file contains
Code:
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.
Code:
CustomerId Long
CustomerName String 30
Re: Change CR Field Value From VB6
Re: Change CR Field Value From VB6
Quote:
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
Re: Change CR Field Value From VB6
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
Re: Change CR Field Value From VB6
Quote:
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
Re: Change CR Field Value From VB6
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?
Re: Change CR Field Value From VB6
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.
Re: Change CR Field Value From VB6
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...
Re: Change CR Field Value From VB6
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...