Solved

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

Posted on 2001-06-25
8
231 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

21 Experts available now in Live!

Get 1:1 Help Now