I'm trying to qualify a field based on a date. If the frequency of the data is supposed to be weekly, I want to select one specific weekend date. If the frequency is monthly, I want the frequency to include the specific weekend date and all weeks thereafter. However, my statement below returns a blank table when False ("Monthly"). I'm guessing there's some specific formatting I have to do to the >= but I'm drawing a blank. Any suggestions?
=IIf([Frequency]="Weekly",[WK_end_Date],>=[WK_end_Date])
FYI... the false statement works correctly when I input only that specific criteria without the IIF statement.
Thanks,
Mark
You can't use IIf this way. Correct your Where clause like this:
Where
([Frequency] = "Weekly" And [YourDateField] = [WK_end_Date])
Or
([Frequency] <> "Weekly" And [YourDateField] >= [WK_end_Date])
Related
I'm new to Access and I'm building a database here at work to log all production that was done. I was able to make a query form with criteria between a date range, condition, part number and work order. Using a code in the expression builder, these are what is placed in the criterion:
Date range: Between [Forms]![Form Query]![BeginDate] And [Forms]![Form Query]![EndDate]
Part number: Like (IIf(IsNull([Forms]![Form Query]![Part Number]),"*",[Forms]![Form Query]![Part Number]))
Condition: Like (IIf(IsNull([Forms]![Form Query]![Condition]),"*",[Forms]![Form Query]![Condition]))
This is where even when part numbers and condition is empty, the query will display all records. My problem is the date range if I leave it empty (say, I simply wanted to query all of the records), it will return with zero value. I wanted it to make it simple for the user that if I leave the date range empty, it will still show all of the records. I had to temporarily put the date range as required to always return results.
Query form
Query Criteria
All input is appreciated! Thank you so much!
Provide alternate value if date is not input:
Between Nz([Forms]![Form Query]![BeginDate], #1/1/1900#) And Nz([Forms]![Form Query]![EndDate], #12/31/2200#)
For text fields, assuming value is unique and is never part of a longer string, LIKE criteria can just concatenate wildcard:
LIKE [Forms]![Form Query]![Part Number]) & "*"
I'm new to SQL. I'm trying to select records less than the current date which is working however we also have entries where the date field is blank which I need to include in the report. I need to be able to see both the current date AND dates that are blank. Any way to accomplish this?
{LOAN1.XLN-PROMDATE} < CurrentDate()
The correct syntax in crystal would be isnull ({datefield}) or {date field} < {?parameter} isnull is not comparable to a value - null means the absence of data, which is not comparable. Hope that helps
I have a query which filters records based on dates (start date and end date)selected in a previous form. I want the query to filter the specific date range, or output all records if the fields are left blank.
I am unfamiliar with SQL. is there a way to add an if-then statement?
I can use vba if necessary, but would like to use the Access GUI if it is possible.
If you have a parameter, used in WHERE clause (Criteria in query builder) and you want to show all records if parameter is empty, just add this parameter as new column and OR condition where indicate Is Null or, better add a column with expression Nz([MyParam],"") and in Condition area inORrow add""`. Unfortunately in query builder this construction may be quite complicated if you have few parameters, in SQL it looks much simpler, for instance in your case it will be something like this:
WHERE (MyDate >= [paramDateStart] and MyDate <= [paramDateEnd])
OR (Nz([paramDateStart],"")="" AND Nz([paramDateEnd],"") = "")
Sometimes simpler edit SQL and then switch to Design view
You can use these criteria for StartDate and EndDate respectively to compare them to themselves in case one (or both) of the search fields on the form is empty (Null):
>=Nz([Forms]![YourForm]![FromDate], [StartDate])
<=Nz([Forms]![YourForm]![ToDate], [EndDate])
I am trying to filter the data returned in a field using multi-value parameters. I need to filter based on 3 conditions:
--Before a Warranty End Date
--AND Service Type on the record must match one of the MULTI-VALUE parameters selected by the user
--AND Order Type on the record must match one of the MULTI-VALUE parameters selected by the user
Currently, this works for the first selection I described above (to sum only those records with a service date <= warranty end date , however, I cannot get the syntax to also check the 2 other fields based on the parameters selected...
Sum(iif(Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value, CDbl(Fields!ExtendedCost.Value), CDbl(0)))
Attached is my layout. Eventually I would like initially display everything to the left of % remaining and allow the user to drill down to see the invoice details
warranty
I don't know what is your reason to use parameter to filter the dataset instead of filter your query directly. However this could be what you are looking for.
Try this:
=Sum(iif(
Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value
AND
Join(Parameters!MultiValSTParam.Value,",").Contains(Fields!ServiceType.Value)
AND
Join(Parameters!MultiValOTParam.Value,",").Contains(Fields!OrderType.Value)
,CDbl(Fields!ExtendedCost.Value)
,CDbl(0)
))
EDIT: Edition based on OP comments.
You should use the parameter to filter the query that is generating your dataset at T-SQL level.
Create #WarrantyEDParam (date type), #ServiceType and #OderType parameters, then use them in your query something similar to this.
select
me.equipment_id,
me.WarrantyEndDate,
me.WarrantyReserveAmnt,
so.invoice_id,
so.service_type,
so.order_type,
so.cost,
so.price
from
master_equipment me
left join sales_order so on me.equipment_id = so.equipment_id
where me.WarrantyEndDate <= #WarrantyEDParam
or so.equipment_id is null --This line was added
and so.service_type in (#ServiceTypeParam)
and so.order_type in (#OrderTypeParam)
Now you will get data filtered directly from the query, so to get the sum of ExtendedCost use:
=Sum(CDbl(Fields!ExtendedCost.Value))
Using Crystal Reports 2011 to reference a View
My formula written as a "formula field"
#mySelection
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN {V_JOB.JOB} ELSE "FALSE"
My record selection written in the "Record Selection Formula"
{V_JOB.LMO} = 'L' AND
{#mySelection}
This View contains several relevant fields. To make my record selection of the view, I want to display all records that are equal to string in .JOB, when string in .TASK like "*IN" and field .DATE = ?myDateRange and field .CLOSED = 'Y'
so I wrote the equation to do exactly that, but the displayed records are row JOB only when TASK,DATE,CLOSED are true. But I have multiple rows of the same JOB where TASK,DATE,CLOSED is false that I also want to see.
So if there are 30 records for Job A and only 1 of those records has #mySelection is "true" then I want to select ALL 30 records even if the other 29 are "false". The way it is written it only displays the 1 true record and not the other 29.
Can anyone provide some assistance on what I'm doing wrong? Is there a "show all" command or perhaps I can save "true" JOBs in an array and then reference the array as my record selection?
Where abouts are you inputting your formula within crystal? It is very important.
You should be able to achieve what you want by using conditional suppression in the details section of your report. Something like this...
//Untested//
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN False ELSE True
This will suppress results where they do not equate to the above conditions.
I found your question a little unclear so this answer might not be perfect for your needs, but hopefully it's a shove in the right direction.
I was able to accomplish this using a sub-report to record select with a parameter reference from the main report
{V_JOB.LMO} = 'L' and
{V_JOB.JOB} = {?Pm-V_JOB_OPERATIONS.JOB}
Then I created a main report and linking a parameter to Job.Job in the sub report and did a record selection for my criteria in the main report.
{V_JOB.TASK} LIKE "*IN"
{V_JOB.CLOSED} = "Y"
{V_JOB.DATE} >= {?FrDate}
{V_JOB.DATE} <= {?ToDate}
I then put the sub-report in the details section but that created a duplicate record issue if there was more than one record for Job.Job that satisfied my selection. So to fix that I created a group for Job.Job, and put the sub-report in the group header and suppressed the detail.
I'm not sure this is the most efficient use of CPU power or the best way to program this in CR, but it gives me the correct results that I need, and relatively quickly for the size of the database.
Your Record Selection forumula should be something like this.
{V_JOB.LMO} = 'L' AND
{V_JOB.JOB}
Now you have all the records in your CR.
Use the below formula as a supression option for the field where you are displaying records.
#Supress
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN true ELSE false
If your condition is true then all records will be displayed else all records will be supressed.
I would suggest you to not to apply these type of conditions in Record selection formula.