Solved

Passing report parameters to a Crystal Report using ASP/RAS & the ActiveX viewer

Posted on 2004-09-18
7
5,331 Views
Last Modified: 2012-06-21
Hello, my company is using crystal reports 9 adv. as it's reporting solution on a ASP/SQL Server company intranet. Currently the reports are viewed through the HTML interactive viewer. This works fine but does not seam to be the most effeicient in regards to printing (multiple steps just to print). It was suggested that we try using the ActiveX viewer as this method provideds a much quicker print time. Crystal recommends using 2 ASP files (rptserver.asp & ActiveXViewer.asp) to view a report, they also say the ActiveX viewer does not support parameter prompts, like the HTML viewers. Using thier suggested method I am able to view our reports that do not have any parameters just fine using the ActiveX viewer, but I am having trouble on how to accept parameters. I am asuming I will need to create a form of some sort to collect the parameters and then pass them to the ActiveX viewer. What to to next is were I am lost. Most of our reports use a start date and end date or a loan number parameter.

I would appreciate any help anyone may have, on using the ActiveX viewer with parameters or suggestions on other reporting methods using Crystal. Below I have attached the code I am using. Thank you


Test page to set the report name in a session variable.

<%
Session("ReportName") = "6mosProgramHistory.rpt"
Response.Redirect("viewers/ActiveXViewer.asp")
%>
**************************************************************

rptserver.asp file

<%@ Language=VBScript %>
<%
' Copyright © 1997-2002 Crystal Decisions, Inc.

Option Explicit

'Create an instance of the object factory.  It is used to create
'report objects more efficiently.
Dim objectFactory
Set objectFactory = Server.CreateObject("CrystalReports.ObjectFactory")

'Check to see if the report has been opened
If Not IsObject(Session("oClientDoc")) Then
      Dim clientDocument
      Set clientDocument = objectFactory.CreateObject("CrystalClientDoc.ReportClientDocument")
      Call CheckForError
      
      'Store the client document in the session for subsequent requests
      Set Session("oClientDoc") = clientDocument
      
      'Support passing the report name in the session or in the URL
      Dim reportName
      reportName = Session("ReportName")
      
      If reportName = "" Then
            reportName = Request.QueryString("rpt")
      End If
      
      If reportName = "" Then
            SetEMFError 1, "A report name was not specified"
            Session.Abandon
            Response.End
      End If
      
      'Open the report
      clientDocument.Open(reportname)
      Call CheckForError      
End if

' Handle the command from the viewer
Dim command
command = UCase(GetArgument("cmd"))

Select Case command
      Case "GET_PG"
            Call GetPage
      Case "GET_TTL"
            Call GetTotaller
      Case "NAV"
            Call Navigate
      Case "CHRT_DD"            
            DrillGraph
      Case "GET_LPG"            
            Call GetLastPage
      Case "SRCH"            
            Call SearchText
      Case "MAP_DD"            
            Call DrillMap
      Case "RFSH"
            Call Refresh
      Case "EXPORT"            
            Call Export
      Case "BSRCH"
            Call BooleanSearch
End Select

'Get Page
Sub GetPage()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.PageRequestContext")
      requestContext.PageNumber = GetPageNumber()

      requestContext.RequestContext = CreateBaseContext()

      On Error Resume Next
      
      Dim EPF            
      EPF = Session("oClientDoc").ReportSource.GetPage(requestContext)

      If LenB(EPF) > 0 Then
            Response.ContentType = "application/x-epf" 'EPF MIME Type
            Response.AddHeader "CONTENT-LENGTH", LenB(EPF)
            Response.BinaryWrite EPF
      Else
            SetEMFError 1, "Unable to generate page."
      End If
End Sub

'Get Totaller
Sub GetTotaller()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.TotallerRequestContext")

      requestContext.RequestContext = CreateBaseContext()

      Dim groupPath
      Set groupPath = objectFactory.CreateObject("CrystalReports.GroupPath")

      Dim path
      path = UCase(GetArgument("TTL_INFO")) 'Used to indicate the group path of the totaller request.
      
      If path <> "" Then
            groupPath.FromString path
      End If

      requestContext.RootGroupPath = groupPath

      On Error Resume Next

      Dim ETF
      ETF = Session("oClientDoc").ReportSource.GetTotaller(requestContext)

      If LenB(ETF) > 0 Then
            Response.ContentType = "application/x-etf" 'ETF MIME Type
            Response.AddHeader "CONTENT-LENGTH", LenB(ETF)
            Response.BinaryWrite ETF
      Else
            SetEMFError 1, "Unable to generate totaller."
      End If
End Sub

'Navigate
Sub Navigate()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.FindGroupRequestContext")

      requestContext.RequestContext = CreateBaseContext()

      Dim groupPath
      Set groupPath = objectFactory.CreateObject("CrystalReports.GroupPath")

      Dim path
      path = UCase(GetArgument("GRP"))

      If path <> "" Then
            groupPath.FromString path
      End If

      requestContext.GroupPath = groupPath

      Dim pageNumber
      pageNumber = Session("oClientDoc").ReportSource.FindGroup(requestContext)
      
      SetEMFPageNumber pageNumber
End Sub

'Drill Graph
Sub DrillGraph()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.DrillDownRequestContext")

      Dim pageRequestContext
      Set pageRequestContext = objectFactory.CreateObject("CrystalReports.PageRequestContext")
      pageRequestContext.PageNumber = GetPageNumber()

      requestContext.PageRequestContext = pageRequestContext

      pageRequestContext.RequestContext = CreateBaseContext()

      Dim COORD
      COORD = UCase(GetArgument("COORD"))      ' these are the coordinates on the graph to process
      Dim XPosition, YPosition
      Call GetDrillDownCoordinates(COORD, XPosition, YPosition)

      requestContext.XPosition = XPosition
      requestContext.YPosition = YPosition

      On Error Resume Next

      Dim totallerNodeID
      Set totallerNodeID = Session("oClientDoc").ReportSource.DrillGraph(requestContext)

      If IsObject(totallerNodeID) Then
            Dim groupName, groupPath
            groupName = totallerNodeID.GroupName
            groupPath = totallerNodeID.GroupPath.ToString

            SetEMFGroupInfo groupName, groupPath
      Else
            Err.Clear
            SetEMFError 40, "Drill down not possible."
      End If
End Sub

'Drill Map
Sub DrillMap()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.DrillDownRequestContext")

      Dim pageRequestContext
      Set pageRequestContext = objectFactory.CreateObject("CrystalReports.PageRequestContext")
      pageRequestContext.PageNumber = GetPageNumber()

      requestContext.PageRequestContext = pageRequestContext

      pageRequestContext.RequestContext = CreateBaseContext()

      Dim COORD
      COORD = UCase(GetArgument("COORD"))      ' these are the coordinates on the graph to process
      Dim XPosition, YPosition
      Call GetDrillDownCoordinates(COORD, XPosition, YPosition)

      requestContext.XPosition = XPosition
      requestContext.YPosition = YPosition

      On Error Resume Next

      Dim totallerNodeID
      Set totallerNodeID = Session("oClientDoc").ReportSource.DrillMap(requestContext)

      If IsObject(totallerNodeID) Then
            Dim groupName, groupPath
            groupName = totallerNodeID.GroupName
            groupPath = totallerNodeID.GroupPath.ToString

            SetEMFGroupInfo groupName, groupPath
      Else
            Err.Clear
            SetEMFError 40, "Drill down not possible."
      End If
End Sub

'Get Last Page
Sub GetLastPage()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.RequestContext")

      Set requestContext = CreateBaseContext()
      
      Dim pageNumber
      pageNumber = Session("oClientDoc").ReportSource.GetLastPageNumber(requestContext)

      SetEMFPageNumber pageNumber
End Sub

'Search Text
Sub SearchText()
      Dim requestContext
      Set requestContext = objectFactory.CreateObject("CrystalReports.FindTextRequestContext")

      Dim pageRequestContext
      Set pageRequestContext = objectFactory.CreateObject("CrystalReports.PageRequestContext")
      pageRequestContext.PageNumber = GetPageNumber()

      requestContext.PageRequestContext = pageRequestContext

      pageRequestContext.RequestContext = CreateBaseContext()

      requestContext.Text = DecodeUTF8(GetArgument("TEXT"))
      
      Dim searchDirection
      searchDirection = GetArgument("DIR")
      If UCase(searchDirection) = "FOR" Then
            requestContext.SearchDirection = 0
      Else
            requestContext.SearchDirection = 1
      End If

      Dim pageNumber
      pageNumber = Session("oClientDoc").ReportSource.FindText(requestContext)            
      
      if pageNumber > 0 Then
            SetEMFPageNumber pageNumber
      Else
            SetEMFError 33, "The specified text, '" & requestContext.Text & "' was not found in the report."
      End If
End Sub

'Refresh
Sub Refresh()
      Session("oClientDoc").ReportSource.Refresh
      
      'The Java Viewer expects an EPF back containing page 1.
      'The ActiveX Viewer expects an EMF back.
      Dim viewer
      viewer = UCase(GetArgument("VIEWER"))      ' This is the viewer that is calling the server      
      
      If viewer = "JAVA" Then
            Call GetPage
      Else
            SetEMFError 0, ""
      End If
End Sub

'Export
Sub Export()
      Dim exportOptions
      Set exportOptions = objectFactory.CreateObject("CrystalReports.ExportOptions")

      'Determine the export format
      Dim fmt
      fmt = UCase(GetArgument("EXPORT_FMT")) ' Used to specify export format and type.      
      
      Dim charIndex
      charIndex = findChar(fmt, ":")
      
      If charIndex > 0 Then
            Dim exportType
            Dim exportDLLName

            exportType = Mid(fmt, charIndex + 1)
            exportDLLName = UCase(Mid(fmt, 1, charIndex - 1))

            Dim startPage, endPage

            Select Case exportDLLName
                  Case "U2FCR"
                        exportOptions.ExportFormatType = 0 ' Crystal Reports
                        Response.ContentType = "application/x-rpt"
                  Case "CRXF_XLS"
                        Response.ContentType = "application/vnd.ms-excel"
                        If exportType = "10" Then
                              exportOptions.ExportFormatType = 6 ' Microsoft Excel Data Dump
                        Else
                              exportOptions.ExportFormatType = 2 ' Microsoft Excel                        
                        End If
                        
                        GetExportPageRange startPage, endPage
                        If startPage > 0 Then
                              Dim ExcelExportOptions
                              Set ExcelExportOptions = objectFactory.CreateObject("CrystalReports.ExcelExportFormatOptions")
                              ExcelExportOptions.StartPageNumber = startPage
                              ExcelExportOptions.EndPageNumber = endPage
                              
                              exportOptions.FormatOptions = ExcelExportOptions
                        End If            
                  Case "CRXF_WORDW"            
                              exportOptions.ExportFormatType = 1 'Microsoft Word
                              Response.ContentType = "application/msword"
                              
                        GetExportPageRange startPage, endPage
                        If startPage > 0 Then
                              Dim WordExportOptions
                              Set WordExportOptions = objectFactory.CreateObject("CrystalReports.RTFWordExportFormatOptions")
                              WordExportOptions.StartPageNumber = startPage
                              WordExportOptions.EndPageNumber = endPage
                              
                              exportOptions.FormatOptions = WordExportOptions
                        End If                                    
                  Case "CRXF_RTF"      
                        exportOptions.ExportFormatType = 3 'RTF
                        Response.ContentType = "application/rtf"
                        
                        GetExportPageRange startPage, endPage
                        If startPage > 0 Then
                              Dim RTFExportOptions
                              Set RTFExportOptions = objectFactory.CreateObject("CrystalReports.RTFWordExportFormatOptions")
                              RTFExportOptions.StartPageNumber = startPage
                              RTFExportOptions.EndPageNumber = endPage
                              
                              exportOptions.FormatOptions = RTFExportOptions
                        End If                                                      
                  Case "CRXF_PDF"                  
                        exportOptions.ExportFormatType = 5 ' Adobe Acrobat (PDF)
                        Response.ContentType = "application/pdf"                  
                        
                        GetExportPageRange startPage, endPage
                        If startPage > 0 Then
                              Dim PDFExportOptions
                              Set PDFExportOptions = objectFactory.CreateObject("CrystalReports.PDFExportFormatOptions")
                              PDFExportOptions.StartPageNumber = startPage
                              PDFExportOptions.EndPageNumber = endPage
                              
                              exportOptions.FormatOptions = PDFExportOptions
                        End If                                    
                                                
                  'Older Export DLL Names:
                  Case "U2FWORDW"
                        exportOptions.ExportFormatType = 1 'Microsoft Word
                        Response.ContentType = "application/msword"
                  Case "U2FRTF"
                        exportOptions.ExportFormatType = 3 'RTF
                        Response.ContentType = "application/rtf"
                  Case "U2FXLS"
                        exportOptions.ExportFormatType = 2 ' Microsoft Excel
                        Response.ContentType = "application/vnd.ms-excel"
                  Case "U2FPDF"
                        exportOptions.ExportFormatType = 5 ' Adobe Acrobat (PDF)
                        Response.ContentType = "application/pdf"
                  Case Else
                        SetEMFError 1, "Unknown Export Format"
                        Exit Sub
            End Select
      Else
            SetEMFError 1, "Unknown Export Format"      
            Exit Sub
      End If

      Dim requestContext
      Set requestContext = CreateBaseContext()

      On Error Resume Next

      Dim exportContent
      exportContent = Session("oClientDoc").ReportSource.Export(exportOptions, requestContext)
      
      If LenB(exportContent) > 0 Then
            Response.AddHeader "CONTENT-LENGTH", LenB(exportContent)      
            Response.BinaryWrite exportContent
      Else
            SetEMFError 1, "Export failed."
      End If
End Sub

'Boolean Search
Sub BooleanSearch()
      SetEMFError 1, "This feature is not supported."
End Sub


Sub GetExportPageRange(ByRef startPage, ByRef endPage)
      Dim exportOptions
      exportOptions = GetArgument("export_opt")

      startPage = 0
      endPage = 0
      
      If exportOptions = "" Then
            Exit Sub
      End If

      'The export_opt value is formatted as follows:
      '[n-m]  page n to m
      '(-n]   first page to n
      '[n-)      page n to the end
      '(-)    all pages
      
      Dim i, dashIndex
      dashIndex = findChar(exportOptions, "-")
      If      dashIndex = -1 Then
            Exit Sub
      End If
      
      'Check for a starting page
      i = findChar(exportOptions, "[")
      If i <> -1 Then
            startPage = Mid(exportOptions, i + 1, dashIndex - i - 1)
      Else
            startPage = 1
      End If
      
      'Check for an ending page
      i = findChar(exportOptions, "]")
      If i <> -1 Then
            endPage = Mid(exportOptions, dashIndex + 1, i - dashIndex - 1)
      Else
            endPage = -1
      End If
End Sub

Function CreateBaseContext()
      Dim baseContext
      Set baseContext = objectFactory.CreateObject("CrystalReports.RequestContext")

      'Handle the branch information
      Dim branches
      branches = UCase(GetArgument("BRCH"))      ' the branch is a mechanism to determine the drill down level.      
      If branches <> "" Then
            Dim groupPath
            Set groupPath = objectFactory.CreateObject("CrystalReports.GroupPath")

            groupPath.FromString branches
            
            Dim totallerNodeID
            Set totallerNodeID = objectFactory.CreateObject("CrystalReports.TotallerNodeID")
            totallerNodeID.GroupPath = groupPath
            
            baseContext.TotallerNodeID = totallerNodeID
      End If
      
      'Handle the subreport context
      Dim subrpt
      subrpt = DecodeUTF8(GetArgument("SUBRPT")) ' The Out of Place Subreport coordinates.
      
      If subrpt <> "" Then
            Dim charIndexVal, tmpCharIndexVal
            Dim tmpStr
            Dim OOPSSeqNo      'holds the page's OOPS sequence number
            Dim SubName      'holds the subreport name
            Dim subCoords 'holds the coordinates of the OOPS in the main report
            Dim mainRptPageNumber 'holds the page number for the main report in the subrpt parameter      
            Dim XPosition, YPosition
            Dim subreportGroupPath 'holds the group path for the main report in subrpt parameter
      
            ' Obtain the subreport sequence number
            charIndexVal = findChar(subrpt, ":")
            If charIndexVal > 1 Then
                  OOPSSeqNo = Mid(subrpt, 1, charIndexVal - 1)
            End If
            ' Obtain the subreport's name
            tmpStr = Mid(subrpt, charIndexVal + 1)
            charIndexVal = findChar(tmpStr, ":")
            If charIndexVal > 1 Then
                  SubName = Mid(tmpStr, 1, charIndexVal - 1)
            End If
            tmpStr = Mid(tmpStr, charIndexVal + 1)
            charIndexVal = findChar(tmpStr, ":")
            ' Obtain the group path for the Out of Place Subreport
            If charIndexVal > 1 Then
                  subreportGroupPath = Mid(tmpStr, 1, charIndexVal - 1)
            End If
            'Obtain the main report page number after the fourth : character
            tmpStr = Mid(tmpStr,charIndexVal + 1)
            'Get the location of the fourth : seperator
            charIndexVal = findChar(tmpStr, ":")
            mainRptPageNumber = Mid(tmpStr, 1, charIndexVal - 1)
            'Get the coordinates portion of the SUBRPT parameter
            subCoords = Mid(tmpStr, charIndexVal + 1)
            Call GetDrillDownCoordinates(subCoords, XPosition, YPosition)

            'Create the subreport context object and set the values into it
            Dim subreportContext
            Set subreportContext = objectFactory.CreateObject("CrystalReports.SubreportRequestContext")
            
            subreportContext.SubreportName = SubName
            subreportContext.PageNumber = mainRptPageNumber
            subreportContext.XPosition = XPosition
            subreportContext.YPosition = YPosition

            If subreportGroupPath <> "" Then      
                  Dim subrptGroupPath
                  Set subrptGroupPath = objectFactory.CreateObject("CrystalReports.GroupPath")

                  subrptGroupPath.FromString subreportGroupPath
            
                  Dim subrptTotallerNodeID
                  Set subrptTotallerNodeID = objectFactory.CreateObject("CrystalReports.TotallerNodeID")
                  subrptTotallerNodeID.GroupPath = subrptGroupPath

                  subreportContext.TotallerNodeID = subrptTotallerNodeID
            End If
            
            baseContext.SubreportRequestContext = subreportContext
      End If
      
      'Handle any Selection Formula
      Dim sf
      sf = GetArgument("sf")
      If sf <> "" Then
            Dim reportStateInfo
            Set reportStateInfo = objectFactory.CreateObject("CrystalReports.ReportStateInfo")
            reportStateInfo.SelectionFormula = sf
            
            baseContext.ReportStateInfo = reportStateInfo
      End If      
      
      Set CreateBaseContext = baseContext
End Function

Function GetPageNumber()
      Dim pageNumber
      pageNumber = UCase(GetArgument("page"))
      
      ' Check to make sure there is a page requested, if not use 1 as a default
      If pageNumber <> "" And NOT IsNumeric(pageNumber) Then
            pageNumber = "1"
      End If

      GetPageNumber = pageNumber      
End Function

' Helper function to parse coordinates passed by viewers and place into independent variables.
Sub GetDrillDownCoordinates(ByVal strParam, ByRef xCoord, ByRef yCoord)
      Dim liStringLength
      Dim lbDone
      Dim lsBuf
      Dim x

      liStringLength = Len(strParam)
      lbDone = FALSE
      lsBuf = ""
      xCoord = ""
      yCoord = ""
      For x = 1 To liStringLength
            lsBuf = Mid(strParam, x, 1)
            
            'ignore this character
            If lsBuf = "-" Then
                  lsBuf = ""
                  lbDone = True
            End if
            
            If lbDone Then
                  yCoord = yCoord + lsBuf
            Else
                  xCoord = xCoord + lsBuf
            End If
      Next
End Sub

'  Helper function that returns the index of the character in the given string.
Function findChar(findStr, charToFind)
      Dim lenStr
      Dim result
      Dim charCounter
      Dim tmpChar
      
      lenStr = Len(findStr)
      result = -1
      
      If lenStr > 0 Then
            charCounter = 1
            Do While(charCounter <= lenStr)
                  tmpChar = Mid(findStr,charCounter,1)
                  If(tmpChar = charToFind) Then
                        result = charCounter
                        Exit Do
                  End If
                  charCounter = charCounter + 1
            Loop
      End If
      
      findChar = result
End Function      

Sub CheckForEMFHandler()
      '  The oEMF object is a helper object to create EMFs (Ecapsulated Messages) for the viewers.
      '  The viewers use EMFs to display errors and navigate to specific pages of the report.
      '  EMFGEN version 2 is required because it implements the SendBranchesStringEMF method.
      If Not IsObject(Session("oEMF")) Then
         Set Session("oEMF") = Server.CreateObject("CREmfgen.CREmfgen.2")
         Call CheckForError
      End if
End Sub

Sub SetEMFError(errorCode, errorMessage)
      CheckForEMFHandler
      
      Response.ContentType = "application/x-emf" 'EMF MIME Type
      Session("oEMF").SendErrorMsg errorCode, errorMessage
End Sub

Sub SetEMFPageNumber(n)
      CheckForEMFHandler
      
      Response.ContentType = "application/x-emf" 'EMF MIME Type
      Session("oEMF").SendPageNumberRecord n
End Sub

Sub SetEMFGroupInfo(groupName, groupPath)
      CheckForEMFHandler

      Response.ContentType = "application/x-emf" 'EMF MIME Type
      Session("oEMF").GroupName = groupName
      Session("oEMF").SendBranchesStringEMF groupPath
End Sub

Sub CheckForError()
      If Err.Number <> 0 Then
            SetEMFError 1, "Error Occured on Server. " & Err.Number  & " : " & Err.Description
            Response.End
      End if
End Sub

Function DecodeUTF8(ByRef s)
      If s <> "" Then
            CheckForEMFHandler
            
            DecodeUTF8 = UCase(session("oEMF").DecodeUTF8String(s))
      Else
            DecodeUTF8 = s
      End If
End Function

Function GetArgument(argumentName)
      'Preference goes to the Form first, since POST data is the preferred method
      'of transmitting variable-length data
      
      Dim t
      t = Request.Form(argumentName)
      
      If t = "" Then
            t = Request.QueryString(argumentName)
      End If
      
      GetArgument = t
End Function

%>
******************************************************************

ActiveX Viewer file

<HTML>
<HEAD>
<TITLE>Crystal Reports ActiveX Viewer</TITLE>
</HEAD>
<BODY BGCOLOR=C6C6C6 onunload="CallDestroy()" topmargin=0 leftmargin=0>

<OBJECT ID="CRViewer"
      CLASSID="CLSID:2DEF4530-8CE6-41c9-84B6-A54536C90213"
      WIDTH=100% HEIGHT=99%
      CODEBASE="/viewer9/activeXViewer/activexviewer.cab#Version=9,2,0,442" VIEWASTEXT>
<PARAM NAME="EnableRefreshButton" VALUE=1>
<PARAM NAME="EnableGroupTree" VALUE=0>
<PARAM NAME="DisplayGroupTree" VALUE=0>
<PARAM NAME="EnablePrintButton" VALUE=1>
<PARAM NAME="EnableExportButton" VALUE=1>
<PARAM NAME="EnableDrillDown" VALUE=0>
<PARAM NAME="EnableSearchControl" VALUE=0>
<PARAM NAME="EnableAnimationControl" VALUE=0>
<PARAM NAME="EnableZoomControl" VALUE=1>
<PARAM NAME="EnableSelectExpertButton" VALUE=0>
</OBJECT>

<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_Onload
      On Error Resume Next
      Dim webBroker
      Set webBroker = CreateObject("WebReportBroker9.WebReportBroker")
      If ScriptEngineMajorVersion < 2 Then
            window.alert "IE 3.02 users need to get the latest version of VBScript or install IE 4.01 SP1 or newer. Users of Windows 95 additionally need DCOM95.  These files are available at Microsoft's web site."
      else
            Dim webSource
            Set webSource = CreateObject("WebReportSource9.WebReportSource")
            webSource.ReportSource = webBroker
            webSource.URL = "rptserver.asp"
            webSource.PromptOnRefresh = True
            CRViewer.ReportSource = webSource
      End If
      CRViewer.ViewReport
End Sub
-->
</SCRIPT>

<script language="javascript">
function CallDestroy()
{
      window.open("Cleanup.asp");
}
</script>

<OBJECT ID="ReportSource"
      CLASSID="CLSID:934CC260-C5AA-43C4-A657-7B70C5B3DAE1"
      HEIGHT=1% WIDTH=1%
    CODEBASE="/viewer9/activeXViewer/activexviewer.cab#Version=9,2,0,442">
</OBJECT>
<OBJECT ID="ViewHelp"
      CLASSID="CLSID:4B5C9C28-3806-47b5-89A9-93063323160F"
      HEIGHT=1% WIDTH=1%
    CODEBASE="/viewer9/activeXViewer/activexviewer.cab#Version=9,2,0,442">
</OBJECT>
<div>
<!-- This empty div prevents IE from showing a bunch of empty space for the controls above. -->
</div>

</BODY>
</HTML>







0
Comment
Question by:vestamedia
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:TommyTupa
ID: 12097322
I have not had a problem passing parameters to ActiveX viewer.  I use it interchangeably with the other viewers. Please let me know if I'm missing something?

Here is code for my test page which works just fine:

<%@ Language=VBScript CodePage=65001 %>
<!-- #INCLUDE File="dbConn.inc"-->
<%
Dim path, iLen
Dim x, y, ReportName

ReportName = "CRList.rpt"

path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(path, 1) <> "\" And Len(path) <> 0)
iLen = Len(path) - 1
path = Left(path, iLen)
Wend

path = path & ReportName


Set objFactory = CreateObject("CrystalReports.ObjectFactory")
Set Session("oClientDoc") = objFactory.CreateObject("CrystalClientDoc.ReportClientDocument")
Session("oClientDoc").Open path


Session("oClientDoc").databaseController.logon sUser,sPass


'Pass Parameters to the Report Object here.  An error will appear if they are not passed in the correct order or the data types are incorrect.
Passparameter "Department", cstr(request("Dept"))


'Response.Redirect "interactiveViewer.asp"
'Response.Redirect "CrystalReportsViewer.asp"
Response.Redirect "ActiveXViewer.asp"


'This passes parameters to the report.
Public Sub PassParameter(strParamName, ParamValue)  
Dim ParamIndex
Dim objParam
Dim objNewParam
    ParamIndex = Session("oClientDoc").DataDefinition.ParameterFields.Find(strParamName, 0)
    Set objParam = Session("oClientDoc").DataDefinition.ParameterFields.Item(ParamIndex)
    Set objNewParam = objParam.Clone
    objNewParam.CurrentValues.Add ParamValue
    Session("oClientDoc").DataDefController.ParameterFieldController.Modify ParamIndex, objNewParam
End Sub

      %>
0
 

Author Comment

by:vestamedia
ID: 12097564
Is this the only page you need other than the ActiveX viewer? Do I even need the rptserver.asp file?

Aaron
0
 
LVL 13

Accepted Solution

by:
TommyTupa earned 500 total points
ID: 12097604
Yes,  when I remove rptserver.asp from the directory the ActiveX page does not load correctly.  FYI: My querysrv.exe is version 9.2.2.596
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:vestamedia
ID: 12097630
Tommy, thank you very much. I just tried your code and it worked prefectly, and it very simple. Now if I need to pass multiple parameters what changes would I need to do?

Aaron
0
 
LVL 13

Expert Comment

by:TommyTupa
ID: 12097662
Keep passing your parameters to the PassParamter sub like this:

'Pass Parameters to the Report Object here.  An error will appear if they are not passed in the correct order or the data types are incorrect.
Passparameter "Department", cstr(request("Dept"))
Passparameter "CashierID", cint(request("Cashier"))
Passparamter "BeginDate", cdate(Request("BeginDate"))


Or, just to be difficult,  once you have your object set you can throw something together like this to loop through the parameters:

Public Function UpdateParameters
  ON Error Resume next
              Dim x,y
          Dim currValue
        UpdateParameters = ""
                        bValidForm = true
            With Session("oClientDoc").DataDefinition
    For Each field in .parameterfields
                        x = Request(field.displayName(0))
                        y = field.displayName(0)
                  
                        if len(x) <1 or isnull(x) OR INSTR(1,x,"Choose") then
                              ' bValidForm = false
                        Else
                              Select Case field.type
                                Case 1,2,3,4,5,6      ' Number
                                             RequestedValue = Cdbl(x)
                                                 if err > 0 then bvalidForm= false
                                Case 7      ' Currency
                                             RequestedValue = CCur(x)
                                                       if err > 0 then bvalidForm= false
                                Case 8      ' Boolean
                                             RequestedValue = cBool(x)
                                                   if err > 0 then bvalidForm= false
                                    Case 9 ' Date
                                             RequestedValue = cdate(x)
                                                       if err > 0 then bvalidForm= false
                                    Case 10 ' Time
                                             RequestedValue = cdate(x)
                                             if err > 0 then bvalidForm= false
                                    Case 11 'String or Multi-value string
                                             RequestedValue = trim(cstr(x))
                                                   if err > 0 then bvalidForm= false
                                    Case 15 ' DateTime
                                             RequestedValue = cdate(x)
                                                       if err > 0 then bvalidForm= false
                        End Select
                        PassParameter y, RequestedValue
                  End IF
                  Next
            End With
            Set Parameter = Nothing
      End Function

0
 

Author Comment

by:vestamedia
ID: 12097823
You are the awsome Tommy, you have just made about 100 users very happy. The number one complaint with our intranet has been how long it takes just to print out a report using the HTML viewer. I cannot thank you very enough. If I could have given you more points I would have.

Aaron
0
 
LVL 13

Expert Comment

by:TommyTupa
ID: 12097860
Glad to Help.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

707 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now