Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


calling a crystal report through vb6 as a DLL

Posted on 2000-03-21
Medium Priority
Last Modified: 2012-05-04
I would like to write a DLL in vb6 that calls a crystal report when the DLL is called.
Any sample code would be great
thanks in advance
Question by:jtjcomp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 2642503
I have listed down the entire procedure of creating a report using the report designer.The code where the query is fired to the database can be put in a dll and the rest can be put on the form.I hope this helps to solve your problem

for the recordset to be passed to Crystal at runtime u have to follow the following steps

1. When designing the report you have to select custom reports sqlodbc.
2. This will pop up another screen where you have to select Active Data (Field Definitions Only).
3. This will pop another screen called Select data source (data Definition) click on the new option Button
4. This will bring another screen where you have to enter the fields and their data types which are to be shown on the report.Save the file (extension .ttx)
and use that to design your report.
    The report will be a dumb report because you are not connected to any data source at this moment.

The requirement is that you have to use vb6.0 with Crystal 7.0 or you can download the report designer component from the seagate web site for free.

In Vb under the project menu you will have add crystal report click that.

This will bring the designer up say import report and bring the report which you have created above.

Then another screen will pop up which will ask if you need the viewer and if you want it to be the starting form.
Say yes to the viewer wanting option and say no to make the viewer the startup object.

For more than one report you can say no to both the options as you can use the same viewer for all the reports.

The declaration will have something like this

Dim Report As New CrystalReport1
(The report which you have imported
You can give the name you want to give)

Dim cnn1 As New ADODB.Connection
Dim rstTest As ADODB.Recordset
Dim rstUser As ADODB.Recordset
Dim strCnn As String
Dim varDate As Variant
Dim sql As String

Now connect to the database
Private Sub Form_Load()
   ' Open connection.
   strCnn = "Data Source=blackhawk;User=dba;Password=chelios; " 
   Set cnn1 = New ADODB.Connection
   cnn1.Open strCnn

Fire the sql query
sql = "select us.user_guid,us.user_last_name, us.user_first_name,us.user_middle_name,ir.lilevel,ir.listatus," & _
    " ir.palevel,ir.pastatus,ir.swlevel,ir.swstatus,ir.wclevel,ir.wcstatus,ir.scon,ir.pclevel,ir.pcstatus" & _
      " from blackhawk01.dba.users us,blackhawk01.dba.ir_history ir where us.user_guid = ir.student_guid " 

( Open the recordset and dump the recorset with the result of the query)

   Set rstUser = New ADODB.Recordset
   rstUser.CursorType = adOpenKeyset
   rstUser.LockType = adLockOptimistic
   rstUser.Open sql, cnn1, dOpenKeyset, adLockOptimistic

Screen.MousePointer = vbHourglass
(the report source is the report which is created)

CRViewer1.ReportSource = Report
(Set the datasource of the report with the recordset you have created)

Report.Database.SetDataSource rstUser
Screen.MousePointer = vbDefault


Author Comment

ID: 2644522
This is a very good start but i am not using a form at all so i will not be able to use the control crystal report.
I will need to reference crystal reports in the dll itself.

I need this to be a standalone dll that when referenced i can pass the correct variable and the report will print.

for instance:
dim x as new myreportdll

x.variable = "898989" 'this will set up the pass through variable.
x.runreport 'this will call the procedure that actually calls the report

Is this correct to think that this is possible.

I will actually be calling the dll from an asp page.  The report will show nothing on the screen it will just start printing to a specified printer.


Accepted Solution

kthacker earned 600 total points
ID: 2645508
Here is some code to print a crystal report using the crystal API.  No forms needed.  This is documented in crystals developer help file.

    Dim PrintOptions As PEPrintOptions
    Dim LogIn As PELogOnInfo4
    Dim strReportType As String
    Dim Job as Integer
    ' - open print job
    Job = PEOpenPrintJob(strRptName)
    If Job = 0 Then
    End If
    ' - set sql server login paramenters
    If crPESetNthTableLogOnInfo(Job, 0, "" & Chr$(0), "" & Chr$(0), "UserLogin" & Chr$(0), "UserPassword" & Chr$(0), True) = 0 Then
    End If
    ' - tell crystal where to print report to
    ' - use this only if you need to change printing location or print to file
    ' - this example prints to a file
    With PrintOptions
        .StructSize = PE_SIZEOF_PRINT_OPTIONS
        .StartPageN = 0
        .stopPageN = 0
        .nReportCopies = 0
        .collation = 0
        .outputFileName = strRptName & ".ps" & Chr$(0)
    End With
    If PESetPrintOptions(Job, PrintOptions) = 0 Then
    End If
    ' - To change papersize or orientation          
    ' - letter size and portrait orientation
    Printer.PaperSize = vbPRPSLetter
    Printer.Orientation = vbPRORPortrait

    ' - letter size and landscape orientation
    'Printer.PaperSize = vbPRPSLetter
    'Printer.Orientation = vbPRORLandscape
    ' - legal size and portrait orientation
    'Printer.PaperSize = vbPRPSLegal
    'Printer.Orientation = vbPRORPortrait
    ' - tell crystal to print to a printer
    If PEOutputToPrinter(Job, 1) = 0 Then
    End If            
    ' - start print job
    If PEStartPrintJob(Job, 1) = 0 Then
    End If
    Call PEClosePrintJob(Job)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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