Solved

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

Posted on 2001-06-25
8
230 Views
Last Modified: 2007-11-27
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
Comment
Question by:Rog
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6225742
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
 

Expert Comment

by:Twingo
ID: 6227258
Are the paramaters, paramaterfields from a stored procedure or regular parameterfields ?

if regular => DRRYan3 has the anwser
0
 
LVL 8

Author Comment

by:Rog
ID: 6227768
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
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6227779
Rog

That's what my code lets you do.  
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:Twingo
ID: 6227849
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
 
LVL 10

Accepted Solution

by:
arana earned 100 total points
ID: 6228415
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
 
LVL 8

Author Comment

by:Rog
ID: 6232591
This worked out great.  The other answers were good too, but this one was exactly what I was looking for.  Thanks.

Rog
0
 

Expert Comment

by:Twingo
ID: 6234362
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now