I have a form view that displays the ListingID, PropertyID, ListingAgentID, SaleStatusID, EndListDate and AskingPrice from a database in SQL.
I have a DropDownList that displays the LastNames of agents that when selected it returns back the relevent information in the formView corresponding to the selection.
It's working, but the only problem is that each last name in the dropDownList is duplicated as they each have more than one listing. What I need it to do is when selecting one last name from the DropDownList it returns one value in the FormView, while being able to use paging to view different listings from that agent.
The code in the FormView is:
SELECT[ListingID],
[PropertyID],
[ListingAgentID],
[SaleStatusID],
[EndListDate],
[AskingPrice]
FROM [Listings]
WHERE ([ListingID] = #ListingID)
The code in the DropDownList is:
SELECT Agents.LastName,
Listings.ListingID,
Listings.PropertyID,
Listings.ListingAgentID,
Listings.SaleStatusID,
Listings.BeginListDate,
Listings.EndListDate,
Listings.AskingPrice
FROM Agents
INNER JOIN Listings
ON Agents.AgentID = Listings.ListingAgentID
Where ever I try and put a DISTINCT function it returns an error or doesn't work
Thanks
For the dropdown all you need is an ID as value and the LastName to display.
SELECT DISTINCT Agents.LastName FROM Agents INNER JOIN Listings ON Agents.AgentID = Listings.ListingAgentID
Related
I have a single page of master region with detail region. On both region I create the page item (SELCT LIST) of P11_ANOID and column in detail table ANOID (select list). Same list are used in bot page item and column but I want to filter the selected return id from P11_ANOID not present in the list of column. I used the query to filter in column list is
SELECT name d
, id r
from ano
where id != :P11_ANOID
but this can't work the. in this case the list cannot show for where condition? can anyone please help.?
If I understood you correctly, then P11_ANOID Select List item's value isn't "visible" to detail region's LoV query. Read: it isn't in the session state.
What to do? Change "Page action on selection" property for the P11_ANOID item to e.g. Submit or "Redirect and set value".
I am using Visual Studio 2017 and I installed the latest crystal reportviewer (22)
What I want is to click a button and create a report from the customer that is selected in the datagridview and the addresses that are shown in the second datagridview.
I managed to do all that but the problem is that a few fields contain numbers which need to be converted to text. An SQL query I would use to do this would be like:
SELECT c.customer_nr, c.status, s.rename FROM CUSTOMERS c INNER JOIN SETUP s on s.id = c.status WHERE s.afk = 'STA'
In my SETUP database I have the columns ID,AFK and RENAME so if the status would be 1 it would convert to text: "ACTIVE", if status = 2 it would convert to "INACTIVE" for example.
I could do something with a formula field like this:
IF ({c.status} = 1) THEN "ACTIVE" ELSE
IF ({c.status}) = 2 THEN "INACTIVE"
but that is not good because i could add another status or change the name in the database etc.
So then I tried with an SQL expression field and I put something like this:
(
SELECT "SETUP"."RENAME" FROM SETUP
WHERE "SETUP"."AFK" = 'STA' AND "SETUP"."ID" = "CUSTOMERS"."STATUS"
)
There must be something wrong because I get the correct conversion but there is only one address in the database but I get 7 pages all with the same address. There should only be one address like I get when I remove the SQL expression field. Where does it go wrong?
* EDIT *
I found the problem. When I create a new database that contains only unique id's then it works. In my original database I have multiple times the id's 1,2,3,4,5 but with different abbreviations in column AFK. Somehow the query looks for the id value and every time it finds this id no matter the AFK value it generates an entry for the address value.
Maybe in the future I will find out how this exactly works for now I have a workaround.
Create a new table for example CrRepSta and add the following entries:
ID,AFK,RENAME
1,STA,Active
2,STA,Inactive
etc
The new query:
(
SELECT "CrRepSta"."RENAME" FROM CrRepSta
WHERE "CrRepSta"."AFK" = 'STA' AND "CrRepSta"."ID" = "CUSTOMERS"."STATUS"
)
And by the way the statement "CrRepSta"."AFK" = 'STA' is not really needed.
Is it possible to filter this query i a way that there are no duplicates of the product name/id so that the attachment field is only displayed once. I am using this query for a access (sub)report. With this result it is displaying the attachment twice or more (depending how Manny times the same products is selected in the order form).
SELECT OrderDetailsTbl.OrderDetailsID, ProductTbl.ProductID,
ProductTbl.ServiceNaam, ProductTbl.omschrijving
FROM ProductTbl
INNER JOIN OrderDetailsTbl ON ProductTbl.ProductID = OrderDetailsTbl.ProductID;
Solved with : HAVING (((OrderDetailsTbl.OrderID)=[Formulieren]![OrderFrm]![OrderID])); !!
I have an access form that contains two subforms. The main form has three dropdown fields that allow the user to pick what data is displayed in the two linked subforms. The dropdown fields are all unbound as they are referenced in the datasource of the main form.
The SQL of the datasource for the main form is as follows:
SELECT tbl_RptPeriod.RptPrdID, tbl_BusUnits.UnitID, tbl_Categories.CategoryID, tbl_Categories.CategoryTitle, tbl_Categories.CategoryGroup, tbl_Categories.Inactive, tbl_Categories.RptPrdID, tbl_Categories.UnitID
FROM tbl_RptPeriod INNER JOIN (tbl_BusUnits INNER JOIN tbl_Categories ON tbl_BusUnits.UnitID = tbl_Categories.UnitID) ON tbl_RptPeriod.RptPrdID = tbl_Categories.RptPrdID
WHERE (((tbl_RptPeriod.RptPrdID)=[Forms]![Compliance]![cmbReportPeriod]) AND ((tbl_BusUnits.UnitID)=[Forms]![Compliance]![cmbBusinessUnit]) AND ((tbl_Categories.CategoryID)=[Forms]![Compliance]![CategoryTitle]));
This works perfectly to look up records. However, I want the users to be able to add new records to the ones they are looking up. That doesn't work as it should.
I can add records, but then the form elements that I am using to look up the data, specifically RptPrdID,UnitID, and CategoryID are not being populated in the table, thus the new records are unassociated and don't show up if you go to look for them again in the main form after closing it or moving to another record.
This makes sense in so far as the form elements I am using in the "WHERE" criteria of the SQL are unbound, but of course, if I add a new record, I want it to be correctly matched. The user must be able to find the records he adds if he looks up the same criteria again.
Question:
How can I get new records entered in the subforms to have RptPrdID,UnitID, and CategoryID filled in?
UPDATE
SELECT tbl_Activity.CategoryID AS CategoryID_X, tbl_Activity.RptPrdID AS RptPrdID_X, tbl_Activity.UnitID AS UnitID_X, tbl_Categories.SortKey, tbl_Categories.CategoryTitle, tbl_Categories.CategoryGroup, tbl_Categories.Inactive, tbl_Categories.Inactive, tbl_BusUnits.Unit_Name, tbl_RptPeriod.Rep_Month_Nr, tbl_RptPeriod.Rep_Month_Name, tbl_RptPeriod.Rep_Year
FROM tbl_RptPeriod INNER JOIN (tbl_Categories INNER JOIN (tbl_BusUnits INNER JOIN tbl_Activity ON tbl_BusUnits.UnitID = tbl_Activity.UnitID) ON tbl_Categories.CategoryID = tbl_Activity.CategoryID) ON tbl_RptPeriod.RptPrdID = tbl_Activity.RptPrdID
WHERE (((tbl_Activity.CategoryID)=[Forms]![Compliance_EXPERIMENT]![cmbCategoryTitle]) AND ((tbl_Activity.RptPrdID)=[Forms]![Compliance_EXPERIMENT]![cmbReportPeriod]) AND ((tbl_Activity.UnitID)=[Forms]![Compliance_EXPERIMENT]![cmbBusinessUnit]))
ORDER BY tbl_Categories.SortKey;
I had to change the query somewhat, but the key fields are still the same ones, though they are now on a different table.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.RptPrdID_X = Me.cmbReportPeriod
Me.UnitID_X = Me.cmbBusinessUnit
Me.CategoryID_X = Me.cmbCategoryTitle
End Sub
Add code for filling those 3 fields in Before Insert event of main form
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.RptPrdID = Me.cmbReportPeriod
Me.UnitID = Me.cmbBusinessUnit
Me.CategoryID = Me.CategoryTitle
End Sub
Good day. This is a follow-up to a previous question. I have a form with 2 comboboxes where the 2nd one depends on the value in the 1st one. I have the code to show the drop down list in the 2nd combobox but I am unable to select anything but the first entry.
Table 1: name - Supply_Sources, fields - Source_ID(pk), SupplySourceName
Table 2: name - Warehouse_Locations, fields - WLocation_ID(pk), Location_Name
Table 3 (junction): name - SupplySource_WarehouseLocation, fields - Supply_Source_ID(pk), Location_In_ID(pk)
On my form 'frmInventoryReceivedInput' I have cboSupplySource and cboWLocation. I populate cboSupplySource with
SELECT [Supply_Sources].[Source_ID], [Supply_Sources].[SupplySourceName]
FROM Supply_Sources;
The SQL for cboWLocation is:
SELECT SupplySource_WarehouseLocation.Supply_Source_ID,
Warehouse_Locations.Location_Name FROM Warehouse_Locations
INNER JOIN (Supply_Sources INNER JOIN SupplySource_WarehouseLocation
ON Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID)
ON Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE ((( SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
There are 3 options for me in the cboWLocation drop down list (based on cboSupplySource). However, it doesn't matter which one I choose, it defaults to the first one. What do I need to do to be able to choose the other options?
I recreated it and it works OK, the only thing I did differently was create a query with the SQL:
SELECT
SupplySource_WarehouseLocation.Supply_Source_ID, Warehouse_Locations.Location_Name
FROM
Warehouse_Locations INNER JOIN
(Supply_Sources INNER JOIN
SupplySource_WarehouseLocation ON
Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE
(((SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
so I could check that part separately from the UI.
For cboWLocation, I have column widths 0";1", rowSource qry_cbo2, and bound column 2. Try changing your bound column from 1 to 2 and see if that helps.
-Beth