NOT IN in SSRS TextBox - reporting-services

How can I write NOT IN in TextBox expression?
I must check if some field value not belong to some list of strings, and then do some work.
Example:
Iif(SomeField.Value NOT IN ('Text1', 'Text2'), DoSomething, nothing)
I wrote code like this and got error when previewing report, and error was :
Overload resolution failed because no accessible 'Iif' accepts this number of type arguments
How can I do this stuff?

Try this small piece of custom code that accepts a string array. Just paste it into the report code section of the report..
Public Shared Function ValueExists(ByVal arr() as string, checkVal as string)
Dim i As Long
For i = LBound(arr) To UBound(arr)
If arr(i) = checkVal Then
return true
Exit Function
End If
Next i
return false
End Function
Usage would involve splitting the string into an array using the Split function
like so:
=iif(Code.ValueExists(Split("Your,comma,separated,string,in,here",","),"StringYouWantToFind")
,"Your value exists"
,"your value does not exist")

You can simply write the code like this:
Iif(SomeField.Value <> 'Text1' AND Field.Value <> 'Text2' , DoSomething, nothing)

I got this one in one report:
=iif(join(Parameters!Parameter1.Value,",") like "*" & Fields!Field1.Value & "*","Color1","Color2")
This instruction helps me to determine the fill colour of a cell inside a tablix, where:
Parameter1 is a multivalue parameter.
"Join" lets me have a string with all selected values from a multivalue parameter, eg. "value1,value2,value3,value4"
Field1 is the field that contains the values filtered by Parameter1
Color1 is the color if the value of the cell is included in the selection of parameter
else Color2
works well

Related

How to display number values with commas in form

In my Access query, I have the query using a VBA function to figure the value that goes in the query field.
In the form, if the stringval textbox has a value, then I want to compute it, but if not, it should remain empty (null).
Function GetValue(stringval, numval)
Dim result
stringval= stringval & ""
result= IIf(stringval<> "", numval* 1.5, Null)
GetValue = Int(result)
End Function
Now, I have a form that uses this query, and on the form is a textbox that displays the query value. I want the value to be formatted with commas in the numbers for easy reading. Everything I've tried so far does not show any commas.
I've tried:
used Standard for the Format > Formatfor the textbox (in properties)
putting #,###.### in the textbox Format value
putting #,##0.0## in the textbox Format value
changing Data > Text Format but it only gives me Plain Text and Rich Text - no option for numbers.
returning a double from the function
Note: if I don't use a custom VBA function, and write the formula directly into the query, then it does display commas. But when I move the formula into the function then the commas are lost.
What do I do?
[update]
I tried Gustav's solutions and since they didn't work for me, I added those as items to my "what I've tried" list above.
Also, if I look at the query in datasheet view, the number values sort alphabetically instead of by the size of the value. When I used the forumulae directly in the query instead of using functions, it sorted by the value of the number. I hope this is a clue.
Numbers carries no format. A format is applied when displayed only.
But be sure to return a Double if not Null:
Function GetValue(stringval, numval)
Dim result
If stringval & "" <> "" Then
result = Int(CDbl(numval) * 1.5)
Else
result = Null
End If
GetValue = result
End Function
Then apply your Format to the textbox
#,##0.0##
Or force a formatted string to be returned:
If stringval & "" <> "" Then
result = Format(Int(CDbl(numval) * 1.5), "#,##0.0##")
Else
result = Null
End If
and skip formatting of the textbox.
The solution is this: the function has to be declared as a double.
That allows the query's datasheet view to know it is displaying numbers - and so you can set the field's format to Standard for the comma to display. This also allows the form to know it has a number and it will display the comma there, too. I knew it had to do with double, but didn't realize before that the function needed to be declared as such.
Function GetValue(stringval, numval) as double '<----THIS!!!!
Dim result
If stringval & "" <> "" Then
result = numval * 1.5
Else
result = 0 `<--can't return null here; use nz function in control source for textbox
End If
GetValue = int(result) 'to remove decimals
End Function
The problem I was having was in some of my functions I need to return double or null, because I wanted textboxes to remain blank if they contained no data. Now, at least I know how to make the numbers generated by functions to display commas.
And here is how to deal with the fact that you can't return null as the value of a double. The function is originally from here.
Put this function in a module so it is public, and then in the control source for the textbox, instead of just putting the field value, put Zn(fieldvalue). This works like a charm (although using functions in the control source seems to have a delay on the form display). This way you can keep the underlying value as a double and still get commas to display in both the form and the query whilst keeping the field blank if necessary.
Public Function Zn(pvar)
' Return null if input is zero or ""
If IsNull(pvar) Then
Zn = Null
ElseIf IsNumeric(pvar) Then
If pvar = 0 Then
Zn = Null
Else
Zn = pvar
End If
Else
If Len(pvar) = 0 Then
Zn = Null
Else
Zn = pvar
End If
End If
End Function

Access Combobox Not In List Event Not finding Added Record

I'm trying to add a record to a ComboxBox source when the entered item isn't in the list.
The code correctly creates the record and then returns Response = acDataErrAdded but still displays the error Item not in list. And if I then manually scroll down the list the new user record is there!
tblUsers
ID(Auto Number), UserCode(Text), UserName(Text)
1, ID00001, "Tom Jones"
2, ID00007, "Fred Smith"
cmbUsers
RowSource = SELECT UserCode, UserName, ID FROM tblUsers
Bound Column = 3
Column Count = 3
Column Widths = "2cm;4cm;2cm"
Input Mask "ID00000;;_"
Private Sub cmbUsers_NotInList(NewData as string, Response as integer)
dim sUserCode as string
sUserCode = "ID" & NewData ' Doesn't have the "ID" ?!?!?
if ActiveDirectoryUserIDExists(sUserCode) then
AddNewUserFromActiveDirectory sUserCode
Response = acDataErrAdded
exit sub
end if
Response = acDataErrDisplay
End Sub
When NotInList is entered the NewData value is 00001 and is not prepended with the input mask "ID".
So I suspect that when the NotInList sub returns Access is using NewData value that is not prepended with "ID" so never finds the value is the re-queried list!
I have tried setting the NewData value to "ID" & NewData before exiting but this did not work.
So I'm really not sure!
Any ideas on how I can get this to work?
InputMask details
The docs for InputMask property say this regarding the second section for InputMask property:
If you use 0 for this section, all literal display characters (for example, the parentheses in a phone number input mask) are stored with the value; if you enter 1 or leave this section blank, only characters typed into the control are stored.
Example:
Input Mask: "ID"00000;0;_
This should cause the entire text value, e.g. "ID00001", to be passed to NotInList event handler in the NewData parameter.
Buggy InputMask behavior for bound ComboBox control
After extensive testing, it seems that this only works flawlessly for an unbound control. If the datatype of the column in the Control Source property does not support saving the fully formatted text value, then the text input value will be formatted to be compatible with (i.e. match) the bound field datatype even though the displayed text is not what is actually saved in the field. This is the best description I could come up with and I could not find any direct resolution to this bug.
So if the bound column is of text type (e.g. Short Text) then there is no problem. But as in the original question where the bound field is a foreign key column of Long Integer type (Control Source: [Assigned User]; Bound Column: 3; Row Source has [ID] as third column), then the input value is converted to a numerical string value before being passed to NotInList.
Workaround
This preserves the desired behavior of the ComboBox and InputMask with minimal code and one extra hidden TextBox control.
Add a simple bound TextBox control for the numeric foreign key field with the following properties:
Control Name: [Foreign_Key_Column_Name]
Control Source: [Foreign_Key_Column_Name]
Visible: False
Add unbound ComboBox control setup with InputMask property and NotInList event handler:
Control Name: [X_Foreign_Key_Column_Name]
Control Source: < Blank / null >
InputMask: "ID"00000;0;_
Row Source: SELECT UserCode, UserName, ID FROM tblUsers
Bound Column: 3 (this is not the same as the Control Source property binding to the form record source and apparently not what causes the buggy behavior)
Add NotInList event handler to unbound control with same code as before.
Private Sub X_Foreign_Key_Column_Name_NotInList(NewData as string, Response as integer)
dim sUserCode as string
sUserCode = NewData
if ActiveDirectoryUserIDExists(sUserCode) then
AddNewUserFromActiveDirectory sUserCode
Response = acDataErrAdded
Else
Response = acDataErrDisplay
end if
End Sub
Add the following code to manually bind the ComboBox value to the numeric foreign-key column.
Private Sub Form_Current()
Me.X_Foreign_Key_Column_Name.Value = Me.Foreign_Key_Column_Name.Value
End Sub
Private Sub X_Foreign_Key_Column_Name_AfterUpdate()
Me.Foreign_Key_Column_Name.Value = Me.X_Foreign_Key_Column_Name.Value
End Sub

Multi-value parameters in ssrs

I have a multi-value parameter. how I get one by one values from this parameter.
value=new_index and label=new_french
and want to insert these values into these labels
You can access the individually selected multi-value parameters by their index (the index is zero-based). So if you want the first selected parameter value (for example, to put it into a label), you can address it like so:
=Parameters!MyParameter.Value(0)
You could access them all using custom code:
Function DoSomething (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
For i As integer = 0 To parameter.Count-1
Result = Result + CStr(parameter.Value(i)) + ", "
Next
Result = Left(Result, Result.Length - 2)
Else
Result = CStr(parameter.Value)
End If
Return Result
End Function
then use this expression to access the result:
=Code.DoSomething(Parameters!MyParameter)
Note that you are passing the parameter object here, not the Value property. We access the Value property in the custom code function.

SSIS Convert Blank or other values to Zeros

After applying the unpivot procedure, I have an Amount column that has blanks and other characters ( like "-"). I would like to convert those non-numberic values to zero. I use replace procedure but it only converts one at the time.
Also, I tried to use the following script
/**
Public Overrides Sub Input()_ProcessInputRows(ByVal Row As Input()Buffer)
If Row.ColumnName_IsNull = False Or Row.ColumnName = "" Then
Dim pattern As String = String.Empty
Dim r As Regex = Nothing
pattern = "[^0-9]"
r = New Regex(pattern, RegexOptions.Compiled)
Row.ColumnName = Regex.Replace(Row.ColumnName, pattern, "")
End If
End Sub
**/
but i'm getting error.I don't much about script so maybe I placed in the wrong place. The bottom line is that I need to convert those non-numberic values.
Thank you in advance for your help.
I generally look at regular expressions as a great way to introduce another problem into an existing one.
What I did to simulate your problem was to write a select statement that added 5 rows. 2 with valid numbers, the rest were an empty string, string with spaces and one with a hyphen.
I then wired it up to a Script Component and set the column as read/write
The script I used is as follows. I verified there was a value there and if so, I attempted to convert the value to an integer. If that failed, then I assigned it zero. VB is not my strong suit so if this could have been done more elegantly, please edit my script.
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' Ensure we have data to work with
If Not Row.ColumnName_IsNull Then
' Test whether it's a number or not
' TryCast doesn't work with value types so I'm going the lazy route
Try
' Cast to an integer and then back to string because
' my vb is weak
Row.ColumnName = CStr(CType(Row.ColumnName, Integer))
Catch ex As Exception
Row.ColumnName = 0
End Try
End If
End Sub

Populating multiple values in rdlc reporting

I am using rdlc report, i have a column in database which i want to display in the report.
vehicleDamageArea=1,2,3
In the report I need to mark the placeholders with these values.
=iif((Fields!vehicleDamageArea.Value="3"),Chr(253),Chr(168)) like this.
But as we know,it will check the whole value 1,2,3="3" not the splitted values.
Any suggestion to check by splitting the vehicleDamageArea parameter.
I made it to work as below
Public Shared Function CheckValue(ByVal InString As String,ByVal input as String) As Char
Dim output As String = String.Empty
Dim Parts() As String = InString.ToString().Split(",")
For i As Integer = 0 To Parts.Length - 1
If Parts(i) = input Then
output = Chr(0120)
Exit For
Else
output = Chr(0111)
End If
Next i
Return output
End Function
You can get the individual values using the split function in reporting services. It returns a zero-based string array, so for your example you need
=Split(First(Fields!ID.Value),",")(2)
You should make a function that accept a comma separated expression, than process this string and return a Boolean, then call this function as for boolean value.