Crystal Report - Suppressing formula based on two conditions - sql

I am new to crystal report & i stuck in a condition which is not executing due to improper coding. so please help me to resolve this.
Thanks in advance.
Here in my report I wanted to display the sales person name but there are 2 categories in sales person i.e Product & Vertical.
P-XXX-James Koren
V-YYY-BBB-Aditi N
Here I just wanted to pick the sales person name in both categories & for that I used mid function as : Mid({Salesperson Name},11,155) this is for vertical sales person, and for product sales person i used mid function as Mid({Salesperson Name},7,155) both are working fine.
but I wanted to suppress the vertical sales person name if the sales order belongs to product person & vice versa
I tried If condition but its not working properly please insist me for how to combine the 2 formulas & suppress one formula if 2 formulas are evaluated.

you can use if condition on suppress like
If
({your field} = "P" and //product or you can use the query here to find P
PageNumber > 1)
then false //don't Supress
else true //Supress
you can use the same formula on other field's suppress like
If
({your field} = "V" and //Vertical or you can use the query here to find V
PageNumber > 1)
then false //don't Supress
else true //Supress

Related

Make an MS Access Report label visible based on data in the report's record source query

In MS Access, I have a report based on a query that presents a summary of a medical checkup. I would like labels for each test to be visible ONLY when those tests were performed. For example, if Glucose was performed on a patient, then the label "lblGlucose" should appear in the report, next to the result. The results currently are present in the report, the problem is when a test is not performed the label is always present. This gives the patient a feeling that the testing was not performed correctly.
To hide the labels I have tried the following approaches:
Private Sub Report_Load()
'1st approach: Lookup column [GLUCOSE] from query qrySummary if not null then set visible property of label lblGLUCOSE to True, else set property to False
IIF(IsNotNull(DLookup("[GLUCOSE]", "qrySummary")),Me!lblGLUCOSE.Visible = True,Me!lblGLUCOSE.Visible = False)
'2nd approach: If value of field [GLUCOSE_RSLT] from table tblResults make textbox txtGlucose visible. FYI: Table tblResults is the table that holds all the results of all the test performed. The query qrySummary derives from this table.
Me!txtGlucose.Visible = Not IsNull([tblResults]![GLUCOSE_RSLT])
'3rd approach: Count column [GLUCOSE], from query qrySummary and if greater than 0 then label lblBHClbl visible
End Sub
I'm still coding the 3rd approach but I'm pretty much running out of ideas and getting nowhere. For first two approaches I get field or expression not found. I don't need for all approaches to work, just one, -in fact, I'm open to other ideas on how I can accomplish the above task.
Any help would be ENORMOUSLY appreciated! Thanks a million!
I'm sharing my DB structure for better understanding
The SQL statement for the summary report is:
PARAMETERS [Forms]![frmIngresoEmpleados]![IDChequeo] Long;
SELECT TblClienteCorp.NombreEmpresa, TblClienteCorp.Direccion, tblChequeo.IDChequeo, tblChequeo.FechaMuestreo, tblChequeo.ChequeoPeriodico, qryCountGenero.*, tblEmpleadosClienteCorp.Genero, tblResultados.Aud_RSLT, tblResultados.Otos_RSLT, tblResultados.AV_RSLT, tblResultados.EKG_RSLT, tblResultados.FR_RSLT, tblResultados.TGP_RSLT, tblResultados.TGO_RSLT, tblResultados.CS_RSLT, tblResultados.ESP_RSLT, tblResultados.PB_RSLT, tblResultados.BHC_RSLT, tblResultados.Plaquetas_RSLT, tblResultados.EGO_RSLT, tblResultados.EGH_RSLT, tblResultados.VDRL_RSLT, tblResultados.Gluc_RSLT, tblResultados.Col_RSLT, tblResultados.EFEC_RSLT, tblResultados.PL_RSLT, tblResultados.Derm_RSLT, tblResultados.Isop_RSLT, tblResultados.BAAR_RSLT, tblResultados.ExFarin_RSLT, tblResultados.Lep_RSLT, tblResultados.Copro_RSLT, tblResultados.Osteo_RSLT, tblResultados.RX_RSLT, tblResultados.US_RSLT
FROM TblClienteCorp INNER JOIN ((tblChequeo INNER JOIN (tblEmpleadosClienteCorp INNER JOIN qryCountGenero ON tblEmpleadosClienteCorp.IDEmpleado = qryCountGenero.IDEmpleado) ON tblChequeo.IDChequeo = tblEmpleadosClienteCorp.IDChequeo) INNER JOIN tblResultados ON tblEmpleadosClienteCorp.IDEmpleado = tblResultados.IDEmpleados) ON TblClienteCorp.IDClienteCorp = tblChequeo.IDClienteCorp
WHERE (((tblChequeo.IDChequeo)=[Forms]![frmIngresoEmpleados]![IDChequeo]));
Within the report that is one query per test, which is:
PARAMETERS [Forms]![frmIngresoEmpleados]![IDChequeo] Long;
SELECT Count(tblResultados.IDEmpleados) AS CuentaDeIDEmpleados, tblResultados.Gluc_RSLT, tblEmpleadosClienteCorp.IDChequeo
FROM tblEmpleadosClienteCorp INNER JOIN tblResultados ON tblEmpleadosClienteCorp.IDEmpleado = tblResultados.IDEmpleados
GROUP BY tblResultados.Gluc_RSLT, tblEmpleadosClienteCorp.IDChequeo
HAVING (((tblResultados.Gluc_RSLT)="P") AND ((tblEmpleadosClienteCorp.IDChequeo)=[Forms]![frmIngresoEmpleados]![IDChequeo]));
If qrySummary has multiple patient records, need WHERE CONDITION criteria:
Me.lblGlucose.Visible = Not IsNull(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID))
However, VBA is not necessary. Calculate in textbox (or in query and bind textbox to calculated field) and set control with transparent BorderStyle. Options:
show "None" text when no data:
=Nz(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID), "None").
instead of label, use a textbox with expression:
=IIf(IsNull(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID)), "", "Glucose")

MS Access Cascading Combo box against a single table, then store the resultant ID

Using MS Access, I have a table called "Locations" and a table called "Routes". I want to create a form that will basically present the routes table to the user (i.e select "from" and select "to") and will filter the "to" locations based on what the user has selected for the "from" location, i.e. a cascading combo box. The corresponding "Route.ID" will be stored in a resultant table on completion of the form.
Location has the following columns -
ID
Name
Notes
1
London
Great Britain
2
Manchester
Great Britain
3
Alabama
USA
Routes has the following columns -
ID
From_LID
To_LID
KM
Notes
1
1
2
450
Using the M1 route
2
2
1
450
Using the M1 route
3
1
2
485
Using the inside routes
4
2
1
485
Using the inside routes
5
1
3
5450
Too far to consider
6
3
1
5450
Too far to consider
I want to create a form with a cascading combo box - "ComboFrom", "ComboTo". Where "ComboFrom" will search the table for a list of distinct IDs, and using a JOIN with the Locations table, I can display the location names. "ComboTo" is dependant on the ID value in "ComboFrom" and will therefore only return a list of locations where it matches the From_LocationID of the routes table.
I have the first part more or less done. ComboFrom has the below query:
SELECT DISTINCT Location.Location_ID, Location.[Location Name], Location.Description
FROM Location INNER JOIN Route ON Location.Location_ID = Route.From_LID
ORDER BY Location.[Location Name];
ComboTo has the below query:
SELECT Location.Location_ID, Location.[Location Name], Location.Description, Route.From_LID
FROM Location INNER JOIN Route ON Location.Location_ID = Route.To_LID
WHERE (((Route.From_LID)=[Forms]![fmrRoute1]![From_LID]))
ORDER BY Location.[Location Name];
The piece of code in the "Where" clause in the ComboTo field basically gets the input of the ID from ComboFrom and outputs the correct IDs from the corresponding To_LID list. I then add vba against the update events for ComboFrom to requery ComboTo field.
What I am having trouble figuring out is how I can get the corresponding route ID to display correctly. i.e if I choose "1" for ComboFrom, and "3" for ComboTo, the Route ID should show "5" and not "7" (where "7" is a new record in the Routes table). Do I have to have a separate query to search for ComboFrom and ComboTo and return the resultant Routes ID? If so, how do I do this and attach it to the field in the form that will automatically update every time the ComboFrom and ComboTo fields change?
Is there a better way to do what I am trying to do?
Thanks in advance for any assistance!
This looks like cascading combo boxes into filtering a form from those two unbound combo boxes.
You can google those two ideas.
The self join made this tricky. The key was ignoring the relationship between Location.ID and From_LID. That relationship is in the database but ignored (deleted) in the query.
this gives us the sql we will need for the second combo box record source.
SELECT Routes.From_LID, Routes.To_LID, First(Locations.LocationName) AS FirstOfLocationName
FROM Locations INNER JOIN Routes ON Locations.ID = Routes.To_LID
GROUP BY Routes.From_LID, Routes.To_LID
HAVING (((Routes.From_LID)=2))
ORDER BY First(Locations.LocationName)
'just need to replace the 2
Private Sub cmbFrom_AfterUpdate()
'cascade combobox
Dim strRowSource As String
strRowSource = "SELECT Routes.From_LID, Routes.To_LID, First(Locations.LocationName) AS FirstOfLocationName" & _
" FROM Locations INNER JOIN Routes ON Locations.ID = Routes.To_LID " & _
"GROUP BY Routes.From_LID, Routes.To_LID " & _
"HAVING (((Routes.From_LID) = " & Me.cmbFrom & "))" & _
"ORDER BY First(Locations.LocationName)"
Debug.Print strRowSource
Me.cmbTo.RowSource = strRowSource
Me.cmbTo.Visible = True
'a look and feel choice
End Sub
[![enter image description here][2]][2]
Private Sub cmbTo_AfterUpdate()
'filter form 'most of the time you want to create a search form where you filter to the records you want
Me.Filter = "From_LID = " & Me.cmbFrom & " AND To_LID = " & Me.cmbTo
Me.FilterOn = True
Me.Detail.Visible = True
End Sub

Can I use a report paramater as a section of the WHERE clause

I have a query that runs great as is like this
WHERE (customer IN (#cust))
and #cust is a customer or a multiple list of customers
what I want to add is an AND with more in another optional parameter like
No: #expiring = " "
OR
Yes: #expiring = " AND getDate() >= dateAdd(d,[expiryWarning],[expiryDate]) "
then I want to add that to the end of the WHERE and have it do that second part if it's chosen from the dropdown as Yes or No so I can show the whole list of customers or just the ones expiring in the report.
WHERE (customer IN (#cust)) #expiring
but I am seeing an error when I try to run this report
that there's an error near #expiring
any insight? I've been searching all day, is this even possible?
You need to change your where clause to take #expiring into account like this.
WHERE customer in (#cust)
AND (#expiring='No' OR getDate() >= dateAdd(d,[expiryWarning],[expiryDate]))
So if #expring is 'No' then that part of the WHERE clause always returns true. If expiring = 'Yes' then the date criteria must be true else that part will return false.

Suppress ENTIRE customer if they contain 1 shipment within a range

Hopefully this makes sense. First post here.
I am trying to suppress all instances of a parent while my parameters affect only the child. I run into a problem where I would like to see all customers that had a shipment outside of a date range and ONLY the customers with shipments outside of that range.
With my current formula below, I will return customers with shipments outside of that date range, but it is possible they have a shipment inside it as well.
Ex.
{customer.arcustname} ={?Customer}
AND
{jobshipment.ccdate} <> {?DateRange}
DateRange = 7/1/2014 to 7/31/2014
CUST1's last shipment was on 6/25/2014, this record returns true
CUST2 has a shipment on 7/25/2014, this record returns false
CUST2 also a shipment on 6/25/2014, this record returns true and is displayed on my report. -not wanted
I would like my report to display only CUST1, since CUST2 had a shipment inside of that range, but my report is showing CUST1 and CUST2 because it is only filtering the {jobshipment.ccdate} and not the entire {customer.arcustname}.
Any help would be appreciated. Thanks!
EDIT: In my details all I have is {customer.arcustname}. All I want my report to display is a list of customers (by salesperson prompt) who have not ordered in a designated time period. All answers I've seen are only showing the shipments not in the range, where I just want to see the customers who have not had a shipment in the date range. If they had a shipment, I want the {customer.arcustname} omitted from my report.
HERE is the raw SQL:
SELECT customer."armasterid",customer."arcustname",
salesperson."arsalesname",jobshipment."ccdate"
FROM ( ( "public".customer customer LEFT OUTER JOIN "public".salesperson
salesperson ON customer.arsalesid=salesperson.arsalesid ) LEFT
OUTER JOIN "public".job job ON customer.armasterid=job.armasterid )
LEFT OUTER JOIN "public".jobshipment jobshipment ON
job.ccmasterid=jobshipment.ccmasterid
WHERE ((#NUMBER CONSTANT# = customer."arsalesid")) AND ((NOT (
(customer."araccountstatus" = 'I') )))
ORDER BY customer."arcustname"
Below solution works assuming you have a customer group and placed dates in detail as you haven't mentioned report structure.
Create a formula #count to count the occurences of dates that are not in range.
if {jobshipment.ccdate} <> {?DateRange}
then 0
else 1
2.Now create a summary field (named {#countSummary}) where we take the sum of #count. Place that in the group footer
3.Write the below supress condition in supress part of group header (Customer group), details and group footer (Customer group).
EvaluateAfter({#count});
if ({#countSummary}) <> 0
then true
else false

Group By for Combobox Filter Sort

I've created a basic Combobox Filter Sort that sorts through Company Regions for my company (Acronyns mostly) we refer to these as AOR's or Area of Reference. After defining your AOR, it limits the next combo box to show only Countries in that specific AOR, hense the Filter Sort. But, my problem is - when it displays the countries after selecting an AOR - It displays ALL RECORDS in that specific country, instead of just 1 country listing.
Basically, It isn't grouping my countries - and when I select "Totals" which normally gives me only unique results, this doesnt work.
My question, How can I re-write this code to include a Group By?
My Code:
Private Sub cboRegion_AfterUpdate()
' Region -> Country
Dim sManagerSource As String
sManagerSource = "SELECT [FullEmail].[AORID], [FullEmail].[ID], [FullEmail].[Country] " & _
"FROM FullEmail " & _
"WHERE [AORID] = " & Me.cboRegion.Value
Me.cboCountry.RowSource = sManagerSource
Me.cboCountry.Requery
End Sub
My SQL statement looks like this (It's got Group By in it, but it doesn't GROUP)
SELECT FullEmail.AORID, FullEmail.ID, FullEmail.Country
FROM FullEmail
GROUP BY FullEmail.AORID, FullEmail.ID, FullEmail.Country
HAVING (((FullEmail.AORID)=1));
Thanks in advance for reading through!
The previous answer is correct, except with a having clause you need to use aggregates... so just use where.
SELECT Country
FROM FullEmail
WHERE AORID=1
GROUP BY Country;
That should fix you up. When you use HAVING it looks at what you've selected, since you didn't select AORID, it didn't know what to do.