jk
یک شنبه 26 آذر 1385, 09:43 صبح
1) You must enable the "Crystal ActiveX Report Viewer Library 11.0" in the CONTROLS tab of PROJECT - COMPONENTS. A new object will appear in the VB6 TOOLBOX section (the REPORT VIEWER ocx).
2) Create a new form named "FRMCRYSTAL" (frmCrystal.frm) and add the Crystal object into it. The report viewer window will appear inside your form. Put the following lines in its LOAD event:
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
Set its "VISIBLE" property to FALSE and close the form.
2) To open and display an external Crystal XI report, you may use these lines in any place of your program:
I'll divide the task in 4:
2.1) point and open the report;
2.2) change the report parameters;
2.3) change the report SQL query; and
2.4) view the report.
2.1) Let's open the external file.The second parameter ("1") means NO-EXCLUSIVE open or TEMP-COPY open.
If you change for zero (EXCLUSIVE), the report will open just once per session.
Dim MyApp As New CRAXDRT.Application
Dim MyRpt As New CRAXDRT.Report
Set MyRpt = MyApp.OpenReport("c:\windows\sample.rpt", 1)
2.2) Let's change some parameters. Interesting to note the FORMULAFIELD syntax, where I can name my text-fields instead to utilize their indexes (easier to work on than the Business Solution's Crystal manual). Obviously, the name between parenteses must reflect the exact formula/text/field name. In that example, the formulas are STRING type.
MyRpt.ReportTitle = "That's my Title!"
MyRpt.FormulaFields.GetItemByName("InitialDate").Text = "'Initial Day: " & dr1(0).Value & "' "
MyRpt.FormulaFields.GetItemByName("FinalDate").Text = "'Final Day: " & dr1(1).Value & "' "
2.3) Change the report SQL query...
x = 100 : y = 1000
MyRpt.SQLQueryString = "select * from dropouts where InitialIssue <= " & x & " and FinalIssue >= " & y
2.4) Finally, log on your server and database. Since your report already exist and has the appropriated fields and layout, you must use the same database and login info present in the report. In my example, you must change the names for your correct ones.
MyRpt.Database.Tables(1).SetLogOnInfo "<server>", "<database>", "<login>", "<password>"
MyRpt.Database.Verify 'required!!!
' And voilá !!! Show the report!!!
frmCrystal.CRViewer1.ReportSource = MyRpt
frmCrystal.Show
frmCrystal.CRViewer1.ViewReport
' Clear memo...
Set MyRpt = Nothing
Set MyApp = Nothing
2) Create a new form named "FRMCRYSTAL" (frmCrystal.frm) and add the Crystal object into it. The report viewer window will appear inside your form. Put the following lines in its LOAD event:
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
Set its "VISIBLE" property to FALSE and close the form.
2) To open and display an external Crystal XI report, you may use these lines in any place of your program:
I'll divide the task in 4:
2.1) point and open the report;
2.2) change the report parameters;
2.3) change the report SQL query; and
2.4) view the report.
2.1) Let's open the external file.The second parameter ("1") means NO-EXCLUSIVE open or TEMP-COPY open.
If you change for zero (EXCLUSIVE), the report will open just once per session.
Dim MyApp As New CRAXDRT.Application
Dim MyRpt As New CRAXDRT.Report
Set MyRpt = MyApp.OpenReport("c:\windows\sample.rpt", 1)
2.2) Let's change some parameters. Interesting to note the FORMULAFIELD syntax, where I can name my text-fields instead to utilize their indexes (easier to work on than the Business Solution's Crystal manual). Obviously, the name between parenteses must reflect the exact formula/text/field name. In that example, the formulas are STRING type.
MyRpt.ReportTitle = "That's my Title!"
MyRpt.FormulaFields.GetItemByName("InitialDate").Text = "'Initial Day: " & dr1(0).Value & "' "
MyRpt.FormulaFields.GetItemByName("FinalDate").Text = "'Final Day: " & dr1(1).Value & "' "
2.3) Change the report SQL query...
x = 100 : y = 1000
MyRpt.SQLQueryString = "select * from dropouts where InitialIssue <= " & x & " and FinalIssue >= " & y
2.4) Finally, log on your server and database. Since your report already exist and has the appropriated fields and layout, you must use the same database and login info present in the report. In my example, you must change the names for your correct ones.
MyRpt.Database.Tables(1).SetLogOnInfo "<server>", "<database>", "<login>", "<password>"
MyRpt.Database.Verify 'required!!!
' And voilá !!! Show the report!!!
frmCrystal.CRViewer1.ReportSource = MyRpt
frmCrystal.Show
frmCrystal.CRViewer1.ViewReport
' Clear memo...
Set MyRpt = Nothing
Set MyApp = Nothing