ms access before change macro not working - ms-access

I am trying to use Microsoft Access data macro:
IF [Dataset_Used]='VS' And IsNull([VS_File]) Then
RaiseError
Error Number: 4002
Error Description: Please choose a VS file
Above macro is working. But if I add And [Note]<>'no file' to the If condition
[Dataset_Used]='VS' And IsNull([VS_File]) And [Note]<>'no file',
the macro will not work. Working means the error description will be displayed when If condition is met.

Try this condition:
And Nz([Note])<>'no file'
Quite sure [Note] field contains mostly Nulls. Null is a special case, Null <> "something" equals Null, not True or False. True And Null gives also Null. But True Or Null gives True.

Related

How to set default value of Boolean parameter false in SSRS?

I have 18 Boolean parameters in my report. I want to make their default value to false through expression when ever user runs the report.
I am trying this but its not working
=SIDIdNum.Value = "false"
Getting Error: parameter SIDIdNum caontain an error [BC30451]
Have you tried just...
false
I'm also not sure where you're trying to set this value? If you are accessing the parameter from somewhere other than parameter properties dialog, you'll need to use
Parameters!SIDIdNum.Value="false"
I had to tweak the prior answer in SSRS 2012.
I needed to make the value: =false

Expression giving error in SSRS

I am using below expression in SSRS but is not giving expected result.
=IIf(Fields!Completed_Date.Value Is Nothing,
Nothing,
IIf(First(Fields!TIMEFORMAT.Value,"dsPreferences") = True,
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy hh:mm:ss tt"),
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy HH:mm:ss")
)
)
It has to check if Date is null.If it is null just leave field blank.If it is not null then it has to return value according to Time zone value that it is getting from another dataset.This expression works fine when there is non null date but it returns #error when there is Null date.
Try using this syntax:
=IIf(IsNothing(Fields!Completed_Date.Value), "", <yourFalsePart>)
This syntax probably doesn't solve your issue because Completed_Date is also used in the false part. IIf operator will always evaluate both expressions before deciding which one to use: so if Completed_Date is Nothing it will broke your expression anyway.
Try using a Custom Function as explained here: SSRS expression giving error with iif condition

Dealing with blank or null in ssrs

In my report, I have an expression which is used to pass a parameter to a child report parameter which is set to allow null values. The expression is :
=IIf(Parameters!Lead.Value = "False",Nothing,Fields!Paid.Value)
The above expression returns values only when Fields!Paid.Value is not blank. Therefore when Fields!Paid.Value is blank I get an error
"the value provided for the report parameter is not valid"
How do I modify my expression to parse these two conflicting issues?
What I want is to be able to return values when the Fields!Paid.Value is blank or when it is not. So at all time when the expression runs corresponding values are returned without the error stated above.
Thanks for helping out.
The first thing you do, wherever you have used the "Paid" parameter, set it to allow null value. Allow null only not blank.
The second thing about the expression, use something like this,
=IIF(Parameters!Lead.Value "FALSE", Nothing, IIF(IsNothing(Fields!Paid.Value),0,Fields!Paid.Value)

Access: Data Type Mismatch using boolean function in query criteria

I have a VBA function IsValidEmail() that returns a boolean. I have a query that calls this function: Expr1: IsValidEmail([E-Mail]). When I run the query, it shows -1 for True and 0 for False. So far so good.
Now I want to filter the query to only show invalid emails. I'm using the Query Designer, so I just add a value of 0 to the Criteria field. This gives me a "Data Type Mismatch" error. So does "0" (with quotes) and False. How am I supposed to specify criteria for a boolean function?
For a boolean column, "0" will definitely give you the "Data type mismatch in criteria expression" error. However, 0 or False without quotes should work. I don't understand why they are generating the same error.
See if you can produce a working query by editing the SQL directly. Create a new query, switch to SQL View and paste in this statement (replacing YourTableName with the name of your table).
SELECT IsValidEmail([E-Mail]) AS valid_email
FROM YourTableName
WHERE IsValidEmail([E-Mail]) = False;
Will your query run without error when you create it that way?
Update: Since that query also produced the same error, all I can suggest is trying this one without any criteria.
SELECT
IsValidEmail([E-Mail]) AS valid_email,
TypeName(IsValidEmail([E-Mail])) AS type_of_valid_email
FROM YourTableName;
However, that seems like a long shot because you already told us your earlier attempt without criteria ran without error. If this doesn't identify the problem, would you consider emailing me a stripped down copy of your database? Let me know if you're interested and I'll give you my email address.
The error was caused by the fact that some of the records in my table have a null E-Mail. My query has a where condition to exclude null E-Mail records, so when I ran it with no condition on the IsValidEmail column my function was only called for records with a non-null E-Mail. However, when I added the condition on IsValidEmail it called the function for every record, and the error came from trying to pass null to a function expecting a string.
Another way to say all that:
SELECT [E-Mail],
IsValidEmail([E-Mail]) <--Executed only for rows matching where clause
FROM Contacts
WHERE IsValidEmail([E-Mail]) = False; <-- Gets executed for all rows
Changing my query expression from IsValidEmail([E-Mail]) to IsValidEmail(nz([E-Mail],"X")) resolved the issue.

Problem evaluating NULL in an IIF statement (Access)

Item in the recordset rstImportData("Flat Size") is = Null
With that, given the following statement:
IIF(IsNull(rstImportData("Flat Size")), Null, cstr(rstImportData("Flat Size")))
Result: Throws error 94: Invalid use of Null
If I change the statement by removing the type conversion upon a false comparison:
IIF(IsNull(rstImportData("Flat Size")), Null, 0)
Result: Null
It returns Null as it should have the first time. It appears that I cannot do a type conversion in an IIF if the value passed in should ever be null even if it passes an IIF test, it still attempts to evaluate it at both the true and false answer. The only reason I'm using IIF like this is because I have a 25 line comparison to compare data from an Import against a matching record in a database to see if I need to append the prior to history.
Any thoughts? The way data is imported there will be null dates and where the spreadsheet import is in a string format I must convert either side to the other to compare the values properly but if either side is null this exception occurs :(
EDIT
Example of why I was using IIF (and considering using a universal function)
If master("one") <> import("one") Or _
master("two") <> import("two") Or _
master("date") <> import("date") Or _ //import("date") comes from a spreadsheet, it comes in as string, CAN be a null value
master("qty") <> import("qty") Or _ //import("qty") comes from spreadsheet, comes in as a string can CAN be null
master("etc") <> import("etc") Then
....stuff....
End If
This code expands for roughly 20 columns to compare in the database. I would prefer to check as part of the statement. I can think of a bunch of solutions but they involve adding much more code. If that is the case power to it, however I'm not one to give in so easily.
Options I see are
Creating temp vars to do the work prior to comparing and using these new vars instead of the recordset
Creating an object to pass the record into to preformat and work with, though extra work would provide this functionality to each import type since there are different files with similar fields
I'm here for ideas, and I'm open to any interesting pieces that can be thrown my way as I get to decide how to do it I'm looking for the most reusable approach.
The simple expedient of changing the value to a string helps tremendously. The trick is that trimming a string which is NULL will get a null string. Which can then be operated on as if it wasn't a database null.
I frequently use the form:
CInt("0" & Trim(SomeVariant & " "))
To get a valid number without having to go through a bunch of hijinks. The null is a nonentity for this problem.
The behavior you described is the standard way IIf operates under VBA. This is part of what Access 2003 Help says about it:
"IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True."
However, if you use an IIf statement in a query, evaluation short circuits after truepart when expr is True --- falsepart is not evaluated in that case. Unfortunately this information is not useful for you ... unless you can incorporate a query into your comparison.
I don't know of any other way to avoid your error with IIf. I would try appending the Excel data into a table whose structure matches that of the table you will compare against, thereby eliminating the need to do a string conversion at the same time you do the comparison.