I wanted to quickly outline a process for passing a condition to a Crystal report in two simple steps. Say you've created an account report that you want to launch via a button on the account detail, limited to the current account record.
Step 1, Setting up the button:
The button is going to do two things: Set the current accountid to a global variable, and launch the report.
Sub Button1Click(Sender)
Application.BasicFunctions.GlobalInfoSet "gAccountID", Application.BasicFunctions.CurrentAccountID
Application.BasicFunctions.DoInvoke "CrystalReportPreview", "Account:New Account Report"
End Sub
Step 2, pass the current ID to the launched report:
In order to pass the ID to the report, we need to create a VB Script which grabs the Global Variable, then passes it to the report using the ReportAddCondition function found under Application.BasicFunctions. This script is attached to the report via the report properties set under manage|Crystal Reports.
The new script is named Account Report Add Condition, and contains:
Sub Main
Dim AccID
AccID = Application.BasicFunctions.GlobalInfoFor("gAccountID")
Application.BasicFunctions.ReportAddCondition "AccountID", "=", AccID, "String", ""
Application.BasicFunctions.GlobalInfoClear "gAccountID")
end sub
Three things are happening here. First of all, we're assigning a local variable to the ID contained in the Global Variable. Next, we add the condition to the report, and finally, we clear the global variable. Once the script is saved, go to the menu item "Manage|Reports", select the report you want to add the condition to and view the properties of the report. On the Execution tab, add the script to the When Open event.
That's all there is to it! You now have a button on account detail which launches your new report for the current opportunity record.