How to show all items in Listbox that is linked to dropdown - ms-access-2010

In an Access Userform I have a listbox that is linked to a dropdown field. In the dropdown field the user can choose a country, and the listbox then updates and shows only the records that are relevant to that country.
I have described how I get the listbox to filter based on the selection in the dropdown in this question here.
While I managed to solve one problem there I created another.
Now when I open the form, the listbox is empty instead of showing all records.
My question: How can I show all records in the listbox to begin with and THEN have the user filter the list based on the dropdown?
The SQL Code in the LIstbox is now the following:
SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country
FROM tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN
GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection
HAVING (((tblISIN_Country_Table.Country)=[Forms]![frmMain]![ddnCountry].[Text]) AND ((tblFUNDS.Fund_Selection)=0));

So I ended up solving this one as well... with a bit of help from an online article which I can now no longer find unfortunately (otherwise I would reference it here):
SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country
FROM tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN
GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection
HAVING (((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0));
The important part is this...
Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0));
Essentially the Nz function lets you return a value when a variant is null. I had it return * which ofcourse is the SQL equivalent of Return All.

Related

Select field from SQL Datasource in Google App Maker based on drop down value

I am running into an issue where I have 3 SQL Datasources (Employee, Course, Overview).
I have created a page inherited from the Overview Datasource, where i have created a drop down (options based on the Employee Datasource Employee.items.Name._equals, value set to Overview.Item.Name). When i select his name in the drop down, I want to dynamically fill in a text field where it selects the email field from the Employee Datasource based on the person selection in the drop-down.
Is this possible? If so, how do I proceed? If further information is required please feel free to ask.
Based on your comment change the following items around.
Overview Datasource dropdown options:
#datasources.Employee.items
Leave your dropdown value the same for now.
Dropdown onValueChange event:
widget.root.descendants.EmailTextBox.value = newValue.Email;
Observe that the newValue is a built in variable in the widgets API for a dropdown and points to an object of the options datasource, therefore, if your options are #datasources.Employee.items the options are an array of objects that make up all the Employee items and when selecting one option it points to items[index] and then you are able to call your object at index with the name of your object item. So newValue.Email should get the selected Employee email.

MS Access Form Not Showing Results

This is truly baffling.
I have a subform that is set up as a continuous form and receives data from a query. Here is the SQL
SELECT Top 12 Tbl_Parent_ITN.ID, Tbl_Parent_ITN.ITN_Number, Tbl_Child_ITN.ITN,
Tbl_Child_ITN.Parent_ITN_fk, Tbl_Scope_Rqmts.Completed, Tbl_Scope_Rqmts.Child_ITN_fk,
Tbl_Lkup_Requirements.Requirement, Tbl_Lkup_Basis.Basis
FROM Tbl_Parent_ITN INNER JOIN (Tbl_Lkup_Requirements
INNER JOIN (Tbl_Lkup_Basis INNER JOIN (Tbl_Child_ITN INNER JOIN Tbl_Scope_Rqmts
ON Tbl_Child_ITN.Id = Tbl_Scope_Rqmts.Child_ITN_fk) ON Tbl_Lkup_Basis.ID = Tbl_Scope_Rqmts.Basis_fk)
ON Tbl_Lkup_Requirements.ID = Tbl_Scope_Rqmts.Requirements_fk)
ON Tbl_Parent_ITN.ID = Tbl_Child_ITN.Parent_ITN_fk
WHERE (((Tbl_Parent_ITN.ID)=[Forms]![Frm_Parent_ITN_Main]![parent_id]));
The criteria in the where clause of the SQL is passed based on the control in the form that precedes this form. The value is the primary key of the parent table that joins with several child tables to get all of the data for the subform.
When I open the with one record that has children it works perfectly fine and the form populates with 12 records. However, when I go run the same operation on the next parent record I don't get any results in view even though that parent has 4 child records.
What is really perplexing is that when I run the query independently from opening the form it gives me the exact results that I want based on that 2nd parent record. Furthermore, if I change the subform to a datasheet I still don't get any records; however, I can see the results in the filters of the datasheet form if I select those column headers (but no records show in the form itself). The properties of the subform are the exact same in both cases, so I can't understand what would cause the records to show in the 1st case but not the 2nd??
A few suggestions:
1. Try to do a Me.Refresh to see what happens.
2. Put a break point in the form's OnError event to see is there is something wrong.
3. Check if there is any other data source that may be locking any data that should be refreshed.
4. Verify that the no properties that define the parent-child relationship of the data is being changed during runtime.
5. Check if the parent record id gets refreshed on the OnCurrent event of the form.
Hope this helps,
FunkSoulBrother

GridView not updating when data comes from multiple tables

I have a GridView control that gets data from two tables, the first one contains a primary key, a name (string) and a foreign key to the second table, The second table contains a primary key "referenced by the foreign key mentioned" and a name (string), i was able to display the id, name (first table) and the name (second table) using an inner join but i can't update the data in the tables using the GridView (when pressing update nothing happens at all, or no change occurs).
From what i understand of your question what you have is a situation that you must a apply a nested gridview.
A gridview shows the content of a table (datatable or a collection).
If you want to show other collection that is inside each row of your primary gridview, you will need
to build a second Gridview or listview or repeater to show that information.
with the primary griview you can use the OnItemDataBound to assign the datasource of the nested gridview or what you choose to show that information based in primary key of the row.
Don't bother i found a solution to the problem on Microsoft website, i am sorry i didn't make my question pretty clear and here is a link to what i was looking for: Editing with Template Fields
Maybe after clicking Update you need to call your read method again to refresh your gridview.
something Like:
UpdateMethod()
{
//YOUR UPDATE STUFF
//REBIND DATA WITH UPDATED RECORDS
RefreshMethod(); //YOUR BINDING METHOD TO DATAGRID STUFF
}

ASP.NET DropDownList - How do I handle missing values?

I have a list of values in a SQL Table which are used to popluate a DropDownList, having a unique Integer as the value of each item and a String as the visible text (via SqlDataSource). There is also a third field in the database which is a flag to indicate whether the list item is active or not (inactive items are not shown in the DropDownList)
Selections made in the dropdown are stored in the database as their integer value (as part of a dataset making up the overall record), not the text value.
Over time, the items in the DropDownList may be removed by marking the items as inactive. However, there is still a need to open old records which may have had a now-inactive item as part of it's data...
My question is, what's the best way to ensure that the missing value included in the dropdown for the old record?
The two methods that spring to mind are to either:
Populate DropDownList with only the currently active items and, when loading a record, catch when the app tries to select a value that doesn't exist, go back to the db to see what it should be (the text value) and manually add it into the dropdown.
or...
Populate DropDownList with all list items (both active and inactive), load the record and then programatically remove all the inactive items (execpt for any that are now selected).
Neither of these seem particularly efficient, so I was wondering whether there is a best practice for this kind of thing?
there are so many optimum ways to do that sort of things, i am defining here a couple of them, use any of following if your Drop down list items count is less than 200 , lets say drop down list is of Products
1)
i) Load all Products records in drop down list and hide the inactive ones by setting visible=false
i) When you load a user record than look for its drop down list value if its visible than select it and enjoy, if its not visible than make it visible by setting its property visible=true and select it and also set its index or id in a flag to change its visibility(visible=false) again after your/users required operation performed.
2)
i) load only active Product records in drop down list ii) while loading a user record also load its product details(name, id, inactive_status) using Joins in sql.
iii) check in that user record if item is inactive then add its record in drop down list as you have all its details now with user details record else just select it.
IMPORTANT NOTE: if you drop down list has items in millions than use ADVANCE SEARCH techniques
The first thing I would do is question your business logic - should you be able to make an item inactive if it is being used as a foreign key in an active row elsewhere? If you make it inactive should it not remove all foreign keys as well?
To answer your question though I would go with a variation on the second idea but filtering in the page like that is probably slower than doing directly with SQL so I guess you have something like this at the moment to populate the dropdown
SELECT * FROM Table WHERE Active = 1
You should already have your record and the foreign key value so I would change it to this
SELECT * FROM Table WHERE Active = 1 OR PrimaryKey = [YourForeignKey]
Then you will always have the selected item but should also be fairly efficient.

One gridview - two datasources?

I am working on a co-workers website, and he mistakenly put up a gridview that shows a TypeID instead of the TypeName. I want to put the actual NAME of the type, instead of it's arbitrary ID number, like he has it. I see he has two "ObjectDataSource"'s on the page -- one for Type and one for Item. Items contains the ID of what TYPE the item is, which is all in the Items datasource. He is pulling this ID to populate the gridview. I want to use that ID to pull the NAME form the other data source, and place that NAME into the gridview for that specific column. Can this be done? Can I use two different datasources on a gridview?
If i'm understanding this right, what you have is two datasources that do this:
1) SELECT ID, Item, ItemTypeID FROM Item
2) SELECT ID, ItemType FROM ItemTypes
And you're wanting the Item name and the Item Type displayed in your grid.
To answer your fundamental question if you can use both sources on the grid: yes. But that's not the most efficient way to perform the operation, as you'd need to be walking the second datasource for every line in the first.
A better way would be to join the two datasources together, and only have one.
Modify the SELECT statement for the first datasrouce to be something along these lines:
SELECT i.ID, i.Item, t.ItemType FROM Item i INNER JOIN ItemTypes t ON i.ItemTypeId = t.ID;

Resources