• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Call Report from VB?????? Pass Parameters from application....

I have a report I have been working on in Crystal 8 and have it finished.  The Record selection is as follows:

{Job.Job-ID} >= {?Job-ID} and
{Job.System-ID} = "IMG" and
{Job.Sub-Job-ID} = {?Sub-Job-ID}

Now I need to call the report from VB.  I have the parameter info at hand, but how do I call it?

Thanks in advance
0
Rog D
Asked:
Rog D
  • 3
  • 2
  • 2
  • +1
1 Solution
 
DRRYAN3Commented:
Give this a try

Private Sub Command1_Click()
  Dim crpParamDefs As CRAXDRT.ParameterFieldDefinitions
  Dim crpParamDef As CRAXDRT.ParameterFieldDefinition
  Dim crpSubreport As CRAXDRT.Report
  Set crpParamDefs = Report.ParameterFields
  For Each crpParamDef In crpParamDefs
    With crpParamDef
    Select Case .ParameterFieldName
      Case "MainParam"
        .SetCurrentValue "Main Report Parameter"
      Case "[CustomerID]"
        .SetCurrentValue "Alfki"
    End Select
    End With
  Next
  Report.EnableParameterPrompting = False
  CRViewer1.ReportSource = Report
  CRViewer1.ViewReport
End Sub
0
 
TwingoCommented:
Are the paramaters, paramaterfields from a stored procedure or regular parameterfields ?

if regular => DRRYan3 has the anwser
0
 
Rog DManager Inforamtion SystemsAuthor Commented:
Actually, the parameters I am asking about are neede when I run the program.  Crystal reports asks me to enter them so the report will run.  I am not too familiar with running crystal from VB.  I thought I could just put the crystal control on the VB form or use References then pass along the Record Selection statement changing where the ? variables above are, then print out the report.

Thanks,
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
DRRYAN3Commented:
Rog

That's what my code lets you do.  
0
 
TwingoCommented:
If you put the crystal control in VB use this code :

Userid and Userpwd as strings

CrystalReport1.Connect = "DSN=DatabaseNAME;UID=" & UserID & ";PWD=" & UserPWD

CrystalReport1.ReportFileName = PrintCopyRPTName
CrystalReport1.SelectionFormula = ""
CrystalReport1.ParameterFields(ArrayIndex)[="ParameterName;
NewValue;SetCurrentValue"]

Arrayindex : means  0 for the first parameter,
1 for the second

example : To change the value of the first parameter field in a report (parameter1) to "red" use the following syntax (user will not be prompted to enter a value):
CrystalReport1.ParameterFields(0) = "parameter1;red;TRUE"

To change the value in a Date parameter field use the following syntax (user will not be prompted to enter a value):
CrystalReport1.ParameterFields(0) = "DatePar;Date(1998,12,7);TRUE"

To prompt the user to change the value of the third parameter field in a report (parameter3) use the following syntax (user will be prompted to use the default value set using the NewValue parameter below - "blue"):
CrystalReport1.ParameterFields(2) = "parameter3;blue;FALSE"
0
 
aranaCommented:
try:

CrystalReport1.SelectionFormula ="{Job.Job-ID} >= " & vJOB & " and {Job.System-ID} = 'IMG' and {Job.Sub-Job-ID} = " & vSUBJOBID


JOB and SUBJOBID chould be your variables

be sure to clear the selection formula in your report, because if not above code will be ADDED to your current selection formula you have saved in your report.

that is if you have a selection formula saved in your report and it will be dynamic then erase it from your report and use it in your code.
0
 
Rog DManager Inforamtion SystemsAuthor Commented:
This worked out great.  The other answers were good too, but this one was exactly what I was looking for.  Thanks.

Rog
0
 
TwingoCommented:
Hint : If the number of record of the database get too large, using the selectionFormula may slow down the creation of the report.
This because the client has to do al the work.

Use a stored procedure as Database to your report and the server has to deal with all the selection work.

So for large tables wich you want to select out => use storer procedure ( faster )
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now