Results 1 to 8 of 8

Thread: Insert value into report

  1. #1

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    I want to insert a string into a crystal report field. It is the user's actual name. What type of field do I need on the Crystal Report, and how do I tell VB to send this string to that field?
    Normal is boring...

    smh

  2. #2
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    Insert a parameter in your report

    then when you call the report in VB

    go through the parameters collection for the report and set the new parameter to the required value.


    Regards

    Chris
    VB6 VS2005

  3. #3

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    Originally posted by chrisa_uk

    go through the parameters collection for the report and set the new parameter to the required value.
    Could you show me an example of how to do that?
    Normal is boring...

    smh

  4. #4
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    There are a few ways to do this, but I use the following as I am not sure how to use the others.


    Firstly your project needs to reference craxdrt.dll and and have component crviewer.dll. Now add a crystal report viewer to your form from the tool box.

    you need the following declarations

    Public reportToView As CRAXDRT.Report
    Public subReportToView As CRAXDRT.Report
    Public reportApp As New CRAXDRT.Application
    Public params As CRAXDRT.ParameterFieldDefinitions
    Public param As CRAXDRT.ParameterFieldDefinition

    and then when you load the form:-

    'insert your report name and path in the brackets
    Set reportToView = reportApp.OpenReport(App.Path + "\summary.rpt", 1)

    'if you have a sub report with parameters then you also need to open a sub report

    Set subReportToView = reportToView.OpenSubreport("summary")

    reportToView.EnableParameterPrompting = False
    reportToView.ReadRecords
    Set params = reportToView.ParameterFields

    For Each param In params
    With param
    .ClearCurrentValueAndRange
    'my parameter in CR is called startDate
    If .Name = "{?startDate}" Then
    'send your value here mine is a date
    .AddCurrentValue CDate(Format(startDate, "dd-mmm-yyyy"))
    Else
    'I have another parameter in my report (endate) the parameter must be this

    .AddCurrentValue CDate(Format(endDate, "dd-mmm-yyyy"))
    End If
    End With
    Next

    'open the sub report
    reportToView.OpenSubreport ("summary")


    'same agaim for parameters

    Set params = subReportToView.ParameterFields
    For Each param In params
    With param
    .ClearCurrentValueAndRange
    If .Name = "{?startDate}" Then
    .AddCurrentValue CDate(Format(startDate, "dd-mmm-yyyy"))
    Else
    .AddCurrentValue CDate(Format(endDate, "dd-mmm-yyyy"))
    End If
    End With
    Next

    'display the report
    With rptExpenses
    .ReportSource = reportToView
    .ViewReport
    .Zoom 1
    End With



    Hope this helps

    Regards

    Chris
    VB6 VS2005

  5. #5

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    THANK YOU!!! I have a good start, but I need to use 2 parameters, and I'm not sure how to do this.

    I have to have the following:

    ?OrderDate = sOrderDate (which is working fine)

    AND

    ?ATMID = sATMID (how do I add this in?)


    Thank you again! You are a mindsaver!
    Normal is boring...

    smh

  6. #6

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    Here is the code that I have for the parameters section of the code to explain that a little better:

    For Each param In params
    With param
    .ClearCurrentValueAndRange
    If .Name = "{?OrderDate}" Then
    .AddCurrentValue CDate(Format(sOrderDate, "dd-mmm-yyyy"))
    End If
    If .Name = "{?ATMID}" Then
    .AddCurrentValue sOrderATMID
    End If
    If .Name = "{?UserName}" Then
    .AddCurrentValue strFullName
    End If
    End With
    Next

    The report is pulling the correct orderdate from the database, and the username is correct, but it is pulling all the ATM's for the orderdate, not just the one stored in the sOrderATM variable.
    Normal is boring...

    smh

  7. #7

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    It is giving the correct information, but it is giving 2 pages of the same information. Do you have any idea why?
    Normal is boring...

    smh

  8. #8
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    Does it give 2 pages of the same info if you open it in Crystal Reports or only in VB?

    Regards

    Chris
    VB6 VS2005

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