Queries in access runtime return different result - sql

I have a form with a few controls. The values entered into the controls are passed to the WHERE clause of a query I use to populate a list box on the same form.
Some of the columns that I am filtering on have null values. When the control is left empty, it should pull in all rows unfiltered by that column.
So part of my WHERE clause looks like this:
WHERE
(person.last_name like [Forms]![frmFilterPerson]![txtLastName] & "*"
OR [Forms]![frmFilterPerson]![txtLastName] Is Null)
When I run my application in the full version of access, and I leave the txtLastName control blank, I get back ALL results, including the ones where the last name is null
However, when I run it in Access Runtime, I do not get all results, only the ones that have a value in the table for last name.
Any suggestions on how I can retrieve the rows that have null values while I have a filter in my where clause based on a control on my form?

You can use this old trick - comparing the field with itself:
WHERE
person.last_name Like Nz([Forms]![frmFilterPerson]![txtLastName], person.last_name) & "*"
OR
person.last_name Is Null
Or:
WHERE
person.last_name Like Nz([Forms]![frmFilterPerson]![txtLastName], person.last_name) & "*"
OR
[Forms]![frmFilterPerson]![txtLastName] Is Null

Related

Using Wildcard in query criteria when referencing form input

I am attempting to use a form to initiate and return query results based on user selected criteria (via a series of 24 combo boxes). So, if the user selects from a drop down, the subform requeries and returns results from query with the selected value as a filter. I need the user to be able to select as many or as few criteria as desired. I have that piece working using the following:
In the query that populates the subform, each criteria has:
Like "*" & [Forms]![formname]![cobx_name] & "*"
Like I said, this works. The problem lies in one of the criteria. There is a field that contains a sequential numeric value (from 1 to over 11,000). When I select, say 7, the query returns records with numerical value 7, 17, 27, 37, and so on. I need for the query to use wildcard and return all records when that specific combo box is null, but return only the one record that is equal to the value (i.e. just the record with value 7 for example) that the user selected.
LIKE and wildcard is intended for text not numbers. If you must use dynamic parameterized query, consider this:
BETWEEN Nz([Forms]![formname]![cobx_name], 0) AND Nz([Forms]![formname]![cobx_name], 99999)

How do I get three columns to concatenate into one combo-box in Access 2010

I have a combo-box in an Access 2010 form that I want to show the concatenation of three fields in three separate columns as a result. Currently, I only get the first column to show upon selection even though all three show in the dropdown. The previous questions I have looked at seem to deal with platforms I'm not using.
In a qry, I have the following simple SQL statement that combines all three into a Desc column.
SELECT tblReLetArea.CWHContractNo, tblReLetArea.ReLetAreaLot, tblReLetArea.ReLetAreaName, tblReLetArea.[CWHContractNo] & ": " & [ReLetAreaLot] & " - " & [ReLetAreaName] AS [Desc]
FROM tblReLetArea;
I have attempted variations but nothing changes and I don't get any error messages.
You need to set two things:
The amount of columns in the combobox (combobox.ColumnCount) must be set to 4
The column widths of the combobox (combobox.ColumnWidths) must be set to 0;0;0 to hide the first 3 columns
Note that you could indeed remove the first 3 columns from your query altogether, or reorder the columns. That would influence the availability of the columns in VBA.

DataView - Reverse RowFilter condition

I have a GridView with a customizable filter implemented with RowFilter. For each column, the user can specify a filter criterium. Once all the desired criteria have been set, he clicks on "Apply filter". The criteria for all columns are combined to create the RowFilter expression of the DataView.
Now, I want to implement a "Reverse" option (a check box) which would simply reverse the RowFilter condition of the DataView. My first thought was to simply say:
RowFilter = NOT (original condition)
And that would be it. Apparently not, because of fields with NULL values. For example, if the filter has the condition StatusID = 10, and if some records have the NULL value for StatusID, the condition NOT (StatusID = 10) will not include those records (according to my tests). For one field, I could easily make the change to account for NULL but, when several fields are combined in the condition, it becomes more complicated.
My question: is there a clever way to globally reverse the RowFilter condition when fields with NULL values are involved, or do I have to test for NULL for each individual field?
If I correctly understood your question you want to get the rest of the result set which is not filtered.
I know there is no direct NOT function as you have shown in your pseudo code.
What you can do is get the dataview based on filter first which probably you have already in place like something below:
DataView dv= //Whatever filter you use
Then convert it to a datatable by using DataView.ToTable()
Next you can easily find the difference between these two datatable(s) like
var rowsOnlyInDt1 = dt1.AsEnumerable().Where(r => !dt2.AsEnumerable()
.Any(r2 => r["col1"].Trim().ToLower() == r2["col1"].Trim().ToLower() && r["col2"].Trim().ToLower() == r2["col2"].Trim().ToLower()));
DataTable result = rowsOnlyInDt1.CopyToDataTable();
which is another table and gives you reverse results.

Multisearch form for a query in access

I should make a query in Access that have 4 criteria. If I Run this query by the structure view of the query it works. Then I built a form to insert the criteria in 4 text boxes and get more easy the use of the query. I create the form using the tutorial on the official site of microsoft 1; i tried first the query with only one text box and one criterium and it works; when I use 4 text box, following the tutorial, it doesn't work. The criterium that I use for each field in the query is the follow:
Switch(Not IsNull([Forms]![frmRICmp]![cod]),[Forms]![frmRICmp]![cod])
I tried to use also
IIf(IsNull([Forms]![frmRICmp]![cod]), Like "*", [Forms]![frmRICmp]![cod])
but also in this case it doesn't work.
can someone tell me the right instrtuction to use in the query's criteria
tnks
So if I gather correctly you need to perform a multi search where if any of the boxes are null you would like to return all the values. and more than one text box can be used simultaneously. TO do this you have to amend do the following.
Amend the Query Field (Note i'm referring to field and not criteria)
For the first Text Box Assuming name is COD and Field Name is also COD
If the Current field name is COD insert another field with the same name and amend to
[COD]=[Forms]![frmRICmp]![cod] OR [Forms]![frmRICmp]![cod] Is NULL
then in the criteria field use the following value
TRUE
For the second Text Box Assuming name is COD2 and Field Name is also COD2
If the Current field name is COD2 insert another field with the same name and amend to
[COD2]=[Forms]![frmRICmp]![cod2] OR [Forms]![frmRICmp]![cod2] Is NULL
then in the criteria field use the following value
TRUE
and continue the same process for all 4 text boxes.

Edit first item of dynamic rows in ssrs?

My ssrs has three row groups nested, and in one of the rows the report runs many times.
I'd like to add something simple to the rows, such as "%" at the end, but only on the first row returned, not the rest of the dynamic rows. My idea was to use:
=RowNumber("detailsGroup") but all that returns is one for each row. Is there another SSRS method?
I was also thinking of using the "is" operator and comparing the dynamic values to the First operator, but running the report gave #ERROR.
If you are using groups you should be able to use Previous() function.
EXample:
Group 1 - ClientName
Group 2 - Region
Group 3 - SubRegion
Detail - data for above 3 groups
If I just want to add something in one of the detail data then I would use ..
=Fields!CallReason.Value + IIF(Previous(Fields!ClientName.Value) <> Fields!ClientName.Value , " Add Text For First Line", "")