Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error message after Application is closed down. (Unload)

Status
Not open for further replies.

1x2z3

Programmer
Sep 18, 2003
39
0
0
ZA
Got several Crystal Reports in my application when I look at some of the reports at run time & Exiting my application afterwards the follwing Error Message appears :

VB6 caused an invalid page fault in module CRYSTL32.OCX at 015f:250127fb.
Registers:
EAX=00000000 CS=015f EIP=250127fb EFLGS=00010202
EBX=0064cf78 SS=0167 ESP=007ffa08 EBP=007ffa98
ECX=00000000 DS=0167 ESI=0064cd80 FS=2b7f
EDX=00000001 ES=0167 EDI=00000000 GS=0000
Bytes at CS:EIP:
c7 41 04 00 00 00 00 c3 56 8b f1 83 79 04 00 74
Stack dump:
2500e831 0064cd90 0064cd80 00000000 25003832 0064cd80 25003765 0064cd80 2501ca30 00000001 00000006 017857c8 00492d70 0064cd8c 0000105c 017857c8

What could be the problem with my Crystal Reports when i only looked at one report and exit no problem but if I look at more than 1 report & exit the problem occure.

Make use of Crystal Reports version 4.6.1.0
 
Check their website. I think I ran into this also when I first started using the report viewer. The help shows how to set up the viewer to access a report, but the code is incorrect. My problem was with Crystal 8, so I don't know if this will turn out to be the same problem.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thanks Artiechoke. I`am using Crystal Report Control 4.6 & not the Viewer Control as in Crystal Reports 8. I`ve got Crystal Report 8 as well but don`t now how link a Report to the Crystal Report Viewer. Still new to me (Crystal Reports). Can you give me advise & code how to do it please the I can use CR 8 instead of 4.6.
 
This is probably a little overkill for what you want (or not), but here's a class I made that has a lot of functionality using the report object. This allows you to do all the setup, then pass a report object to the viewer.

Code:
'***************************************************************************************************************
'
'   Name:       CrystalReports
'
'   Purpose:    Allows easy setup of the report object for use in the Crystal reports
viewer
'
'***************************************************************************************************************

Option Explicit

Private Report As CRAXDRT.Report
Private app As New CRAXDRT.Application

'   Store all databases and servers for main report and subreports for easy modification

Private Type ReportConnections
    DatabaseName As String
    ServerName As String
    SubReport As CRAXDRT.Report
    TableNumber As Integer
End Type

Private numConnections As Integer
Private connections(100) As ReportConnections

Enum CrystalValueTypes
    crDate = 1
    crNumber
    crText
End Enum

'***********************************************************************************************
'                                           Properties
'***********************************************************************************************

Property Get ConnectionCount() As Integer

'   Returns the number of connections for main report and subreports

    ConnectionCount = numConnections
    
End Property

Property Get CrystalDate() As Integer

    CrystalDate = crDate
    
End Property

Property Get CrystalNumber() As Integer

    CrystalNumber = crNumber
    
End Property

Property Get CrystalText() As Integer

    CrystalText = crText
    
End Property

Property Get DatabaseName(n As Integer) As String

'   Returns the database name for the selected connection
'   For the main report, also applies to the table name

    If n > 0 And n <= numConnections Then
        DatabaseName = connections(n).DatabaseName
    Else
        DatabaseName = ""
    End If
    
End Property

Property Get ParameterCount() As Integer

    ParameterCount = Report.ParameterFields.count
    
End Property

Property Get ParameterDefault(n As Integer) As String

    ParameterDefault = ""
    If n > 0 And n <= Report.ParameterFields.count Then
        If Report.ParameterFields.Item(n).IsDefaultValueSet Then _
        ParameterDefault = Report.ParameterFields.Item(n).GetNthDefaultValue(1)
    End If
    
End Property

Property Get ParameterName(n As Integer) As String

    If n > 0 And n <= Report.ParameterFields.count Then
        ParameterName = Report.ParameterFields.Item(n).ParameterFieldName
    Else
        ParameterName = ""
    End If
    
End Property

Property Get ParameterPrompt(n As Integer) As String

    If n > 0 And n <= Report.ParameterFields.count Then
        ParameterPrompt = Report.ParameterFields.Item(n).prompt
    Else
        ParameterPrompt = ""
    End If
    
End Property

Property Get ParameterSize(n As Integer) As Integer

    If n > 0 And n <= Report.ParameterFields.count Then
        ParameterSize = Report.ParameterFields.Item(n).NumberOfBytes
    Else
        ParameterSize = 0
    End If
    
End Property

Property Get ParameterType(n As Integer) As Integer

    If n > 0 And n <= Report.ParameterFields.count Then
        Select Case Report.ParameterFields.Item(n).ValueType
            Case crDateField, crDateTimeField
                ParameterType = CrystalDate
            Case crNumberField, crCurrencyField
                ParameterType = CrystalNumber
            Case crStringField
                ParameterType = CrystalText
        End Select
    Else
        ParameterType = -1
    End If
    
End Property

Property Get ReportObj() As CRAXDRT.Report

    Set ReportObj = Report
    
End Property

Property Get ServerName(n As Integer) As String

'   Returns the server name for the selected connection
'   For the main report, also applies to the table name

    If n > 0 And n <= numConnections Then
        ServerName = connections(n).ServerName
    Else
        ServerName = ""
    End If
    
End Property

Property Let SetParameterValue(n As Integer, v As Variant)

    If n > 0 And n <= Report.ParameterFields.count Then
        If Not Report.ParameterFields.Item(1).EnableMultipleValues Then _
        Report.ParameterFields.Item(n).ClearCurrentValueAndRange
        If ParameterType(n) = CrystalDate Then
        
'   Note: date parameters must be passed as a date value
        
            Report.ParameterFields.Item(n).AddCurrentValue CDate(v)
        Else
            Report.ParameterFields.Item(n).AddCurrentValue v
        End If
    End If
    
End Property

Property Get TableCount() As Integer

'   Returns table count for main report only

    TableCount = Report.Database.tables.count
    
End Property

Property Get TableName(n As Integer) As String

'   Returns the table name for the selected table - for main report only

    If n > 0 And n <= Report.Database.tables.count Then
        TableName = Report.Database.tables(n).Name
    Else
        TableName = ""
    End If
    
End Property

'***********************************************************************************************
'                               Public routines
'***********************************************************************************************

Public Function OpenReport(reportName As String) As Integer

    OpenReport = 0
    On Error Resume Next
    
    Set Report = app.OpenReport(reportName)
    If Err.Number <> 0 Then OpenReport = -1
    GetConnections

End Function

Public Sub SetLoginInfo(n As Integer, ServerName As String, Optional DatabaseName
As String = "")

'   Changes the server and optionally the database
'   Not using user login - assumes report is set up for a trusted connection

    Dim whichReport As CRAXDRT.Report
    
    If n > 0 And n <= numConnections Then
    
'   Get the main or subreport as necessary

        If n <= Report.Database.tables.count Then
            Set whichReport = Report
        Else
            Set whichReport = connections(n).SubReport
        End If
        
        If DatabaseName <> "" Then
        
'   Change both server and database names

            whichReport.Database.tables(connections(n).TableNumber).SetLogOnInfo ServerName,
DatabaseName
            connections(n).DatabaseName = DatabaseName
        Else
        
'   Only change server name

            whichReport.Database.tables(connections(n).TableNumber).SetLogOnInfo ServerName
        End If
        connections(n).ServerName = ServerName
    End If

End Sub

Private Sub GetConnections()

'   Gets all the database and server names for the main report and all sub reports

    Dim CRXSection As CRAXDRT.Section
    Dim CRXSubreport As CRAXDRT.Report
    Dim n As Integer
    Dim reportObject As Object
                
'   First get the main report

    numConnections = 0
    For n = 1 To Report.Database.tables.count
        numConnections = numConnections + 1
        connections(numConnections).ServerName = Report.Database.tables(n).LogOnServerName
        connections(numConnections).DatabaseName = Report.Database.tables(n).LogOnDatabaseName
        connections(numConnections).TableNumber = n
    Next
                
'   Now get the subreports

    For Each CRXSection In Report.Sections
        For Each reportObject In CRXSection.ReportObjects
            If reportObject.Kind = crSubreportObject Then
                Set CRXSubreport = reportObject.OpenSubreport
                For n = 1 To CRXSubreport.Database.tables.count
                    numConnections = numConnections + 1
                    Set connections(numConnections).SubReport = CRXSubreport
                    connections(numConnections).ServerName = CRXSubreport.Database.tables(n).LogOnServerName
                    connections(numConnections).DatabaseName = CRXSubreport.Database.tables(n).LogOnDatabaseName
                    connections(numConnections).TableNumber = n
                Next
           End If
        Next
    Next

End Sub


"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thanks Artiechoke, I will try the coding. Hope i did`nt give you a lot of work to do. Thank`s anyway...
 
Nope. Wrote this awhile back. I only had to do a cut and paste! :)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top