Pages

Monday 12 August 2013

Calling cyrstal report from vb6

1. Add two components into project Crystal Report Control and Crystal report viewer control.
2. Add a reference  to the project Crystal Report Activex Designer runtime.
2. Add a form into the project
3. Add a Crystal report control in the form
4. Add a second form from where you need to call the report.

Please confirm  that crystal report 8.5 is installed in your machine.

Set CrysRep = CrysApp.OpenReport(ReportName)

Call CrysRep.Database.AddOLEDBSource("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=sa;Initial Catalog=" & db_name & ";Data Source=" & Srv_Name, m_DefaultTable)
    ' Sql = "SELECT employee_master.emp_code, employee_master.emp_name, SUM(employee_attendance.normal_hours)+100 AS nhrs, SUM(employee_attendance.ot_hours) " & _
" AS othrs, SUM(employee_attendance.incentive_hours) AS incthrs FROM         employee_master INNER JOIN  employee_attendance ON employee_master.emp_id = employee_attendance.emp_id GROUP BY employee_master.emp_code, employee_master.emp_name ORDER BY employee_master.emp_code"
If m_recSet.state = 1 Then m_recSet.close
m_recSet.Open m_SQL, m_Con
With CrysRep
  .Database.Tables(1).SetDataSource m_recSet
  .DiscardSavedData
End With
CRViewer.ReportSource = CrysRep
CRViewer.ViewReport

-------------------------------------------------------------------------

a. Crysrep is the viewer control runtime.

b. Second line gives the connection string for sqlserver, for connection string for oracle visit http://subhroneel.blogspot.in/2013/08/connection-string-to-connect-to.html

c. m_recSet is the ADODB.Recordset

d. CrViewer is the report control name in the form.

e. After CRViewer.ViewReport you need to add formname.Show, the form where the control CRViewer in embeded.

No comments:

Post a Comment