I have an SSRS report which is based on a BAQ Datasource. The BAQ has a number of parameters, some of which are optional and marked in the BAQ as “Skip Condition if Empty”. For example, I am creating a report of shipments over a time period, and entering the customer ID is optional. So, I have parameters of a From Date, a To Date, and a Cust ID which is optional. If they enter a Customer ID, they get just that customer. Or they can leave it blank and it will return all customers.
On the header of my report, I’m listing the parameters that the report ran with. I’m using the built-in Code that’s delivered with the SSRS report to get the prompt values and display them. So for example:
The problem is that when the user doesn’t enter a Customer ID, the parameter doesn’t exist in the RptParameter, the code fails, and on the header it’s showing “error”. I’ve tried various tricks to try to get rid of/hide this. I’ve tried the “IsNothing” function, tried an iif statement with the IsError function, even tried to alter the visibility properties with an IsError function. So far, haven’t hit the magic trick.
Has anyone else dealt with this and have an easy solution. My “workaround” is to make the parameter mandatory, default the value to “ALL”, and have some logic in the BAQ that looks at the value to determine whether to select the records. But I’m thinking there must be a quicker solution without adding complexity to the BAQ.
In those types of situations, I usually found success with an OR in the first part of the IF statement. Something like “IsNothing or = ‘’”. Sorry I can’t be more specific, but I don’t have SSRS at the moment.
Thanks. I checked, and unfortunately that throws an error as well. When I look at the RptParameters UserCriteria field where the function pulls this data from, I think the issue is that the parameter doesn’t show up at all as a prompt, as opposed to being there but being empty.
Note that I have prompts for fromDate, toDate and showDetail (prompts 1, 2 and 5). Prompts 3 and 4 are optional, and since a value wasn’t entered, it’s not even listed in the code. If I had this in the code, I’d be golden. Somehow I need an “exists” type function.
You’re right, it doesn’t work. I’m not sure what I was doing yesterday I tried it once and it seemed to work.
Anyway, another option would be to force it by adding error handling to that function. In SSRS, right click anywhere outside your page and select Report Properties, then select ‘Code’ on the left section.
Replace the function below:
Public Function GetCriteriaPromptValue(ByVal userCriteria As Object, ByVal promptName As String) As String
If Me.promptValues Is Nothing Then
Me.promptValues = FillPromptValues(userCriteria)
End If
Return Me.promptValues(promptName)
End Function
with this one:
Public Function GetCriteriaPromptValue(ByVal userCriteria As Object, ByVal promptName As String) As String
On Error GoTo err1
If Me.promptValues Is Nothing Then
Me.promptValues = FillPromptValues(userCriteria)
End If
Return Me.promptValues(promptName)
err1:
Return ""
End Function
Another option would be to take a closer look at that code than I did and make it work properly.