Results 1 to 16 of 16

Thread: Change CR Field Value From VB6

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    45

    Question 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

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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?

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    45

    Re: Change CR Field Value From VB6

    I am using version 9 of CR

    UserID is a Textbox

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Dim objCrystal As New CRAXDRT.Application
    2. Dim objReport as CRAXDRT.Report
    3. Dim objTextBox as CRAXDRT.TextObject
    4.  
    5. Set objReport = objCrystal.OpenReport(ReportPath, 0)
    6. Set objTextBox = objReport.Sections("Section1").ReportObjects("Text6")
    7. objTextBox.SetText "User Id"
    8.  
    9. 'code to view/print report

    You will need to find the correct Section name and TextObject name used by Crystal.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    45

    Re: Change CR Field Value From VB6

    Could you explain what is entered into the ("Section1") part?

    I am a little confused?!

  7. #7
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    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

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  9. #9
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Change CR Field Value From VB6

    yes thats it

  10. #10
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Change CR Field Value From VB6

    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

  11. #11
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    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

  12. #12
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Change CR Field Value From VB6

    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

  13. #13
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    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?

  14. #14
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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.

  15. #15
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    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...

  16. #16
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width