Multisearch form for a query in access - sql

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.

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)

MS Access - Query - Replace value

One of the fields contains ID of partner organisations. Wherever the field is populated it's one of the partner organisations. If the field is blank, it means it's the parent company. In my query, how can I populate the blank records with the ID of the parent company?
The only thing I found was to create an expression in a new field:
SELECT Valid_Learner.LearnRefNumber, Valid_Learner.FamilyName, Valid_Learner.GivenNames, Valid_Learner.DateOfBirth, Valid_Learner.Ethnicity, Valid_LearningDelivery.FundModel, Valid_LearningDelivery.PartnerUKPRN,
Replace([PartnerUKPRN],"","parentComanyID") AS UKPRN,
Valid_LearningDelivery.DelLocPostCode, Valid_LearningDelivery.LearnAimRef
FROM Valid_Learner RIGHT JOIN Valid_LearningDelivery ON Valid_Learner.LearnRefNumber = Valid_LearningDelivery.LearnRefNumber;
The new field ("UKPRN") should (for the purpose of this question) have the string "parentCompanyID" whenever it's blank in the PartnerUKPRN field.
The result is the UKPRN field displays IDs where the ID is present in the PartnerUKPRN field, but shows "#Error" where it's blank in PartnerUKPRN.
If "blank" means NULL, then you can use NZ() in MS Access:
NZ([PartnerUKPRN], "parentComanyID") AS UKPRN
This would be the "normal" way to write this logic. I don't know why REPLACE() would return an error.

SSRS how to use multiple criteria in expression - based on a row value and a field name

Please look at the image below, my dataset has two processes, 'logs processed' and 'stacked at kilns'.
I need to take the total 'stacked at kilns' and divide it by the total 'logs processed' for each length.
so for example for field name 5.4 (dataset field length), I would like to divide 2784/2283 to return a percentage of the recovery.
my expressions currently is
=Sum(IIf(
(Fields!process.Value = "Logs Processed") AND (Fields!Length.Value=Fields!Length.Value)
, Fields!cubes.Value
, Nothing)
, "Wetmill_to_Kiln")
But this returns the value of all lengths where process is 'Logs Processed' not for just length 5.4 as per example.
So each length field is dynamically created (3.3,3.6,3.9 .... 6,6.3,6.6)
I would like to get the total for 'stacked at kiln'/'logs processed' for each length field.
any help appreciated as always
example of my desired output in bottom image.
current output:
Desired output:
*****UPDATE AS PER TPHE*********
I have created a text box inside the column group. this returns the value for that group but how can I reference the value of that text box.
if I use something like ReportItems!tbxSource.Value how can I reference the value of the textbox when the it is dynamically created across the column group? there are then mulitple instances of that textbox name?
with reference to the picture how do get the value of the white <> from the textbox with green <>
Thanks,
Since you are using a column group, you can put your expression into a text box within the group and it will execute on only the data that is captured within each column. So if your code for the Logs processed row is something like Sum(Logs) and your code for the Stacked at Kiln row is something like Sum(Stacked), your expression code for the recovery row would be Sum(Stacked)/Sum(Logs). The key is to make sure that it is within the column group.
So what I got to work was to create two variables on the column group. one called kilntotal and one called logtotal. the variables value was equal to the result of this expression:
=sum(iif(Fields!process.Value="logs",cdbl(Fields!cubes.Value),cdbl(`0)))`
and
=sum(iif(Fields!process.Value="kiln",cdbl(Fields!cubes.Value),cdbl(0)))
I then use these variable in my logic in my recovery % row:
=Variables!kilntotal.Value/Variables!logtotal.Value
Thanks for the input and your time.

How to assign one same label for multiple value in non-queried available values in ssrs 2005 report?

Parameters - Multiple Values For One Label - Possible?
Sorry my modified Question.....
I have question to ask,...
Is it possible to have multiple values for ONE label in non-queried available values in SSRS 2005? i want to join fields value in a single row like,
Works: (But this bring a long list in drop down menu - which i donot want)
Label Value
---------------------------
Site-1 150
Site-1 151
Site-2 152
Site-2 153
Required result (Which i want - in one line)
Label Value
---------------------------
Site-1 150,151
Site-2 152,153
(which will bring one label and related multi-value in drop down or combo box.
But the problem is that ColumnName IN (#Site) does not work with multi-value.)
More description of the problem:
Let say, I have a field/column
Name = Site
Value = C150,C151, C152, C153
I want drop down menu on report with
C150,C151(as Site-1) & C152,C153(as Site-2)
So I created parameter i.e. #getSite and set values as
multi-value in the report as
Label Value
---------------------------------------------
Site-1 (150,151)
Site-2 (152,153)
And set my parameter as #getSite:= Parameters!#getSite.Value
And Query i wrote as,
SELECT * FROM ..
WHERE Site IN (#getDisease)
But after all these, my report result is empty,literally no result.
It seems like if i select only one value as Site-1 = 150, then it works
but not two or more values in one line,
why it is not possible?? if yes then how?
Please help!!!
Yes just Right Click on your parameter in your Report Data window under Parameters folder and select the check box for allow multiple values as follows
this is what I said before you need to put your column name inside a set of paranthesis something like this
SELECT * FROM ..
WHERE (Site IN (#getDisease))
I have been working on this problem for a while and I think I have finally figured it out...
Basically you need to use a backwards case statement in your SELECT statement, put that in a derived query and then reference it in the outer WHERE clause..
SQL:
SELECT * FROM
(
SELECT
Label
, value
, CASE WHEN [value] IN (150,151) THEN 'site-1' WHEN [value] IN (152,153) THEN 'site-2' END AS [grouped_values]
)
WHERE grouped_values IN (#getSite);
*Note: This answer only works on values that are mutually exclusive, if both sets had the same value included then it would be problematic..
--
Hopefully this can put you in the right direction. I am finding a lot of the reporting services tricks require reverse engineering or at least some reverse thinking.
cheers,
Michael

How to make a drop down list (list box)in an MS Acess Query with values from two different tables

I need the drop down box above to display the date as shown and the ClassTypeDesc as you can see above the dropdown list shows 1/12/2010 twice. They have different ClassTypes Assigned to them.
The drop down list should show:
1/12/2010 ACLS-I Day One AM
1/12/2010 ACLS-I Day One PM
I need to know the statement to put in the Row Source Box on the lookup tab in the Field Properties to make this work.
Related Question on Making a drop down list
There's no need to concatenate the two columns. Based on the diagram, the SQL for your lookup combo box should look like this:
SELECT tblClassSession.SessionID, tblClassSession.Date, tblSessionType.ClassTypeDesc
FROM tblClassSession INNER JOIN tblSessionType
ON tblClassSession.SessionTypeID = tblSessionType.SessionTypeID;
Then in the properties for your lookup combo box, change ColumnCount to 3, and Column Widths to 0 (if you want to size the other columns, change Column Width sto something like 0";.75";1.5", and the List Width property to 2.25").
I may have gotten some of the field names wrong, but that's the basic idea.
(also, you probably really ought to rename tblClassSession.Date to tblClassSession.SessionDate so you don't run into problems with the fact that Date is a reserved word)
As you already have the right number of rows, you just need to concatenate enough fields to make it more useful, so your query would be something like:
SELECT c.Date + ' ' + s.ClassTypeDesc AS YourFieldName
FROM...