p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

crystal_reports thread: Re: Beginner with VB & Crystal Rep 8


Message #1 by "Rodney Derrick" <billyblaq@h...> on Wed, 27 Nov 2002 16:03:33
> > Hi:

> > I'm a new developer with Crystal Reports 8.0 &  VB 6.0. I've already 
d> > efined my report based in a SQL Server view. But I want to know which 
c> > omponent/references I need to declare in my project and also how to 
d> > efine parameters in my report to pass them from my application and 
make 
i> > t a "dynamic report". 
T> > hanks in advance

> > Alma
a> > lma_quiroz_lopez@y...
a> > lma.quiroz@g...

> 
i> 'll try to explain me with an example:

> I add the Crystal Report Control to my proyect, then i add the control 
to 
m> y form and i name it rpt. I make a report with Crystal Reports and i 
name 
i> t report.rpt

> I write the code to show my report:

>   ' In my report i created two parameters: Agency (string) and 
 >  ' PrintVal (boolean).
 >  ' We can pass values to those parameters:
 >  rpt.ParameterFields(0) = "Agency;" & Agency.Text & ";TRUE" 
 >  ' value TRUE: do not asks for the parameter value
 >  rpt.ParameterFields(1) = "PrintVal;TRUE;TRUE"

>   ' We can also set the formulas values:
 >  rpt.Formulas(0) = "Year = '" & Year & "'"

>   ' And we can add sentences to our selection formula:
 >  rpt.SelectionFormula = "{Agency.Code} = '" & Agency.Text & "'" & _
 >            " and {Agency.Dept} = " & Dept.Text
 >  
 >  ' You have to set the report file to the control:
 >  rpt.ReportFileName = App.Path & "\report.rpt"

>   ' And make the connection to the server. 
 >  ' pdssql.dll is the library to connect to a sql server database
 >  
rptSAR.LogOnServer "pdssql.dll", "server", "database", "user", "password"

>   ' I'll show the report on a maximized window
 >  rpt.destination = crptToWindow 
 >  ' You can also print it (crptToPrinter) or send it to a file 
 >  ' (crptToFile) and more options
 >  rpt.WindowState = crptMaximized

>   ' Finally you print the report
 >  rpt.PrintReport

> I don't know if i help you, there are more possibilities to work with CR 
r> eports but i use this.

> Bye,
 >  Miguel

This code worked on my home computer; but when I took it to work, I only 
receive a blank screen.  This code isn't working on any of the machines at 
my work, but it works fine from my home computer.

rpt.ReportTitle = "Breeder Report"
rpt.ReportFileName = "c:\rpt_Breeder_AlphaList.rpt"
rpt.ParameterFields(0) = "@Begin_Date; " & begin_date & "; true"
rpt.ParameterFields(1) = "@End_Date; " & end_date & "; true"
rpt.ParameterFields(2) = "@Permit_Code; " & license_code & "; true"

rpt.LogOnServer "pdssql.dll", "myserver", "db", "thename", "thepass"
rpt.WindowState = crptMaximized

rpt.PrintReport

  Return to Index