Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Astute Commentator
Posts: 16
Registered: ‎04-15-2009

LAN Client, pass logged in userid to Crystal reports

I'm trying to build a report that will filter records automatically based on the logged in userid.
Any idea how can I pass that value to the report?
I'm using the Lan Client, version 8.


Nickel Contributor
Posts: 90
Registered: ‎03-20-2009

Re: LAN Client, pass logged in userid to Crystal reports

[ Edited ]



I am going to assume that you are using the Crystal Obejct?  If not I would suggest you doing so.  here is a snippet of code we use to do this.  Replace objRDC.RecordSelectionFormula value in the code with your logged in UserID and you should get what you want.


(You may have to edit the code to fit your needs...)


I apologize, but in looking at this today, I missed a couple of lines of code at the top and bottom when I cut and pasted, so I updated the information....


Sub DisplayCrystalReport(byVal strReportName, byVal strSelectionFormula, byVal strFileName, byVal blnDisplay)
' To display a crystal report, pass in the file name to save, the report name to dispaly in SalesLogix format, and any Selection criteria to use
' DisplayCrystalReport("Account:Ticket", " {Account.AccountID} = 'A6UJ9A000ZX'", "File Name to Save.pdf", "True")
' Words of caution, the space before the first "{" in the selection formula is critical to getting the dialog boxes to not display!
' and the Selection Formula must be passed into the call in Crystal Reports format.
    Dim objRDC
    Dim objShell
    Dim strMyDocumentPath
    Dim strDiskPathFileName

    ' Set up our file path and name to make it semi-unique....
    strMyDocumentPath = Application.BasicFunctions.GetPersonalDataPath

    strDiskPathFileName = strMyDocumentPath & "\" & Application.BasicFunctions.CurrentUserID & "_" & strFileName

    ' Set the Crystal object
    Set objRDC = Application.BasicFunctions.GetCrystalReport(strReportName)

    ' Establish all the Crystal Report criteria we need to show the report....
    objRDC.ExportOptions.DestinationType = 1 'Disk File
    objRDC.ExportOptions.FormatType = 31 'PDF
    objRDC.ExportOptions.DiskFileName = strDiskPathFileName
    objRDC.ExportOptions.PDFExportAllPages = True

    ' See if we need to work with the Selection Criteria at all....
    If Len(strSelectionFormula) > 0 then
        ' YES we do!!
        If Len(objRDC.RecordSelectionFormula) > 0 then
            ' Something else is already there, handle it....
            objRDC.RecordSelectionFormula = objRDC.RecordSelectionFormula & " and" & vbCRLF & strSelectionFormula
            ' Nothing else was there, just put in what we received....
            objRDC.RecordSelectionFormula = strSelectionFormula
        End if
    End if

    ' Setting this to True will ALWAYS display the pop-up dialog boxes....
    objRDC.Export False

    ' Destroy our Crystal object....
    Set objRDC = Nothing

    ' Do we need to display it? or just write it out?
    If blnDisplay then
        ' Now open the report like we were supposed to do....
        Set objShell = CreateObject("Shell.Application")  'DNL
        objShell.ShellExecute strDiskPathFileName, "", "", "Open", 1  'DNL
        Set objShell = Nothing
    End if
End Sub

Jim Pemberton
Vice President of Engineering
Simplesoft Solutions, Inc
Award Winning Infor CRM Business Partner