the expression you entered contain invalid syntax in access query - ms-access

I am trying to make a query. I don't type anything. I use only every formula by clicking in built-in function of access, but I get this popup error

The function iif requires the condition, iftrue, and iffalse to be separated with a comma, not a colon. Makr it look like this:
Iif(condition, ifTrue, ifFalse)

Related

Can I use IsNothing along with the Lookup function

I'm trying to use the row visibility function in Report Builder 3.0 by using the expression below:
=IIF(IsNothing(Lookup(Fields!Activity.Value,Fields!Activity.Value,Fields!Pred_Activity.Value,"ds_Pred"),True,False)
When I run the report, I get an error message Too many arguments to Public Function isNothing.
Is it possible to use the IsNothing function along with the Lookup function?
Your parenthesis don't line up there for starters, if I'm reading your code correctly, what it should say is: =IIF(IsNothing(Lookup(Fields!Activity.Value,Fields!Activity.Value,Fields!Pred_Activity.Value,"ds_Pred")),True,False)
I just figured it out. The formula was missing the last parenthesis. It should have been:
=IIF(IsNothing(Lookup(Fields!Activity.Value,Fields!Activity.Value,Fields!Pred_Activity.Value,"ds_Pred")),True,False)

The Group expression for the grouping ‘Origin2’ contains an error: Argument 'Length' must be greater or equal to zero. (rsRuntimeErrorInExpression)

I am getting this error every time this report is rendered. I looked at the group expression for this group and it looks like this:
=Trim(Left(Fields!ILS_LS_USER_10.Value,InStr(Fields!ILS_LS_USER_10.Value,"->")-2))
The field ILS_LS_USER_10.Value is: BNST -> USWEOLN
I can't see the error. Can anyone help me diagnose this error, please?
It works if you put the string literal in place of Fields!ILS_LS_USER_10.Value.
The issue is that it isn't getting the value of the field as a string by default. Use the ToString() method after .Value and it should work, or at least it did on my machine.
=Trim(Left(Fields!ILS_LS_USER_10.Value.ToString(),InStr(Fields!ILS_LS_USER_10.Value.ToString(),"->")-2))
I found that the Group expressions, for some reason, do not seem to like the subtraction in the InStr. Leave out the subtraction and it works.
In fact, take the same formula, and place it into a placeholder in the Group and it seems to work just fine. Replaced with Split in the Group expression and it works.
This was on SQL Server 2016, using Report Builder.

How to use Excel Object Model in Access Query Expression?

I am moderate to advanced user of Microsoft Excel, but very new to Microsoft Access (2010 version). What I am trying to do is use Excel functions in an Access Query Expression. So far, I've researched how to set Access to reference the Microsoft Object Model by going to Create/Module/Tools/References and then selecting the Microsoft Excel 15.0 Object Library.
From there, I went to my Query (Design View) and attempted to add an expression in the Field row to calculate the distance between two points. As a test, I typed:
Distance: Excel.WorksheetFunction.ACOS(50)
I thought this would work, but once I closed, saved the Query, and reran the Query I received the following error:
Undefined function 'Excel.WorksheetFunction.ACOS' in expression
I've done some Googling to determine why this isn't working, but have been unsuccessful. I'm not sure if Access allows you to reference Excel directly from the expression. Or, perhaps my syntax is incorrect.
Write a simple function in VBA (in Access) that calls the Excel function you want to use:
public function myTestFunction(x as double) as double
myTestFunction = Excel.WorksheetFunction.ACOS(50)
end function
Use this function in your query:
If you use the query design grid:
Simply write the function in a column and put the column name of the column that holds the input value as the argument. If you want to put an alias to the column, write the alias before and use :; something like this: columnAlias: myTestFunction([OtherColumn])
If you're writing your query using SQL:
Write your query as usual; use the function like any other function available in SQL:
select [OtherColumn], myTestFunction([OtherColumn]) as function
from [YourTable]

LIKE operator in SSRS row visibility expression

I have a text box within an rdl report which I want to suppress based on certain terms in my dataset (i.e. if the query returns a term which ends with the letter "L" then hide the text box).
Within the textbox properties I have set visibility expression for Hidden with the below expression:
=First(Fields!STERMS__.Value, "Job") NOT LIKE '%L'
When I run it I get the error:
"The Visibility.Hidden expression for the text box contains an error:
[BC30201] Expression expected"
It seems like a schoolboy error but I have tried various permutations on this expression with no luck. Any help would be appreciated.
SSRS expressions are funny in some ways. I think what you're looking for is:
=IIf(First(Fields!STERMS__.Value, "Job") Like "*L", True, False)
The gist is that SSRS doesn't use SQL syntax. It's VB
I think you could use the Right() function which returns a specified number of characters from the right hand side of a string.
E.g.
=Right(Fields!STERMS__.Value,1)
I guess in your case for Hidden property on the cell, the expression would look like this
=IIF(Right(First(Fields!STERMS__.Value, "Job"),1)=="L",true,false)

SSRS expression replace NULL with another field value

I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?
=iif(isNothing(Fields!FV1.Value), Fields!FV2.Value, Fields!FV1.Value)
If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:
Right click on the Report Document and go to Report Properties.
Navigate to the Code tab and add the following function:
Public Function IsNull(input As Object, defaultValue As Object) As Object
Return IIf(input Is Nothing, defaultValue, input)
End Function
Note - Even though the custom code is expecting valid VB.NET code, you have to use the IIF Ternary operator.
Then you can use it in an expression like this:
=Code.IsNull(Fields!MyField.Value,0)