Using cascading combo boxes in a datasheet subform - forms

In Access 2010, I have tables Task and Action that have a many-to-many relationship through table ActionTask. In the form for Task, I want to put a subform for all the Actions related to the current task through the ActionTask junction table.
This, in itself, I can do.
The trick is that Action is actually the bottom rank of a four-tier hierarchy of tables.
Each Action belongs to a Goal, each Goal belongs to a Theme, each Theme belongs to a Strategy.
Rather than just have a combo box listing all the available Actions, I'd like to use cascading combo boxes for the Strategy/Theme/Goal/Action.
This I can also do.
The problem is when I use this technique in a datasheet, if I select a given row, the selected row shows the proper Strategy/Theme/Goal/Action, but in all the other rows
the Action is blank
the Strategy/Theme/Goal is set to the current row's values, rather than that row's values
I've tried using the "Continuous Forms" view rather than the "Datasheet" view, but the result is pretty much the same.
I think I know why (the Me.StrategyCombo = ... stuff in my Form_Current callback), but I don't know another way to achieve that.
How can I make the subform display all the rows properly?
Here's the Access file, but all the relevant details should be below.
Tables:
Strategy : (ID, Desc)
Theme : (ID, StrategyID, Desc)
Goal : (ID, ThemeID, Desc)
Action : (ID, GoalID, Desc)
Task : (ID, Desc, ...)
ActionTask : (ActionID, TaskID)
Form Settings:
[Forms]![Task]![ActionTaskSub]:
Link Master Fields: ID
Link Child Fields : TaskID
[Forms]![Task]![ActionTaskSub].[Form]:
On Current:
Private Sub Form_Current()
' when the form loads a record, should reverse propegate
' action > goal > theme > strategy
Dim goalID, themeID, strategyID
' figure out the goal, theme, and strategy that go with this action
If (Me.ActionID) Then
goalID = DLookup("[GoalID]", "Action", "[ID] = " & CStr(Me.ActionID))
themeID = DLookup("[ThemeID]", "Goal", "[ID] = " & CStr(goalID))
strategyID = DLookup("[StrategyID]", "Theme", "[ID] = " & CStr(themeID))
End if
' populate the combo boxes and make the appropriate selections
Me.StrategyCombo = strategyID
Me.ThemeCombo.Requery
Me.ThemeCombo = themeID
Me.GoalCombo.Requery
Me.GoalCombo = goalID
Me.ActionCombo.Requery
Me.ActionCombo = Me.ActionID
End Sub
[Forms]![Task]![ActionTaskSub].[Form]![StrategyCombo]:
Row Source : SELECT [Strategy].[ID], [Strategy].[Desc] FROM [Strategy];
After Update:
Private Sub StrategyCombo_AfterUpdate()
Me.ThemeCombo = Null
Me.ThemeCombo.Requery
Call ThemeCombo_AfterUpdate
End Sub
[Forms]![Task]![ActionTaskSub].[Form]![ThemeCombo]:
Row Source : SELECT [Theme].[ID], [Theme].[Desc] FROM [Theme] WHERE
[Theme].[StrategyID] = [Forms]![Task]![ActionTaskSub].[Form]![StrategyCombo];
After Update:
Private Sub ThemeCombo_AfterUpdate()
Me.GoalCombo = Null
Me.GoalCombo.Requery
Call GoalCombo_AfterUpdate
End Sub
[Forms]![Task]![ActionTaskSub].[Form]![GoalCombo]:
Row Source : SELECT [Goal].[ID], [Goal].[Desc] FROM [Goal] WHERE
[Goal].[ThemeID] = [Forms]![Task]![ActionTaskSub].[Form]![ThemeCombo];
After Update:
Private Sub GoalCombo_AfterUpdate()
Me.ActionCombo = Null
Me.ActionCombo.Requery
End Sub
[Forms]![Task]![ActionTaskSub].[Form]![ActionCombo]:
Row Source : SELECT [Action].[ID], [Action].[Desc] FROM [Action] WHERE
[Action].[GoalID] = [Forms]![Task]![ActionTaskSub].[Form]![GoalCombo];

I solved the issue of dependent (Cascading) comboboxes in a datasheet.
By nature, if combobox 1 is dependent on a value from combobox 2, it will apply the "rowsource" from the current row to all rows in the datatable
Solution:
1 In the load or designer, define the rowsource to include all rows so the datavalue behind it will always match with an option in the rowsource (otherwise you display a blank value)
ie:
Private Sub Form_Load()
Me.cmbProjects.RowSource = "SELECT [Projects].[ProjectPK], [Projects].[ProjectName], [Projects].[PI_ID] FROM [Projects] ORDER BY [ProjectName] "
End Sub
2 In the dependent combobox get focus event, redefine the rowsource to be based on a value from the other combo box that the former depends on. Requery the control
Private Sub cmbProjects_GotFocus()
Me.cmbProjects.RowSource = "SELECT [Projects].[ProjectPK], [Projects].[ProjectName], [Projects].[PI_ID], [Projects].[Status] FROM [Projects] WHERE [PI_ID] = " + CStr(cmbPIs.Value) + " ORDER BY [PI_ID], [ProjectName] "
cmbProjects.Requery
End Sub
3 In the dependent combobox lost focus event, redefine the rowsource to NOT be based on a value from the other combo box that the former depends on.
Private Sub cmbProjects_LostFocus()
Me.cmbProjects.RowSource = "SELECT [Projects].[ProjectPK], [Projects].[ProjectName], [Projects].[PI_ID], [Projects].[Status] FROM [Projects] ORDER BY [PI_ID], [ProjectName] "
cmbProjects.Requery
End Sub

You can't. Any action applies to the subform current record but appears to affect all controls. There are various work-arounds.

As far as I know you can't, but you can work around it by creating a continuous form, putting your fields in tabular layout, then adding a textbox for each combobox (if field is prodID, then I name the textbox txtprodID). Move the textbox right on top of the combobox, but a little narrower, just shy of the combo list arrow, then write code to update the textbox.

Related

libreoffice base create a list filtered by another list's value

I have a table of provinces and a table of cities with ProvienceID. In a form, I want to create a list of cities filtered by selected value of provience list.
How can I do that?
I can create both lists but Cities list shows all cities from all provinces but i want to show only cities from the province that I have selected in Provinces list.
I have another table "Users" with "CityID" and "ProvinceID" that my form edits it and I need to save selected values of Province and City Lists in it, not only show it in the form.
Create two example tables named "Provinces" and "Cities".
ProvinceID Name
~~~~~~~~~~ ~~~~
0 South
1 North
2 Large Midwest
3 Southeast
4 West
CityID Name ProvinceID
~~~~~~ ~~~~ ~~~~~~~~~~
0 Big City 2
1 Very Big City 2
2 Rural Village 1
3 Mountain Heights 0
4 Coastal Plains 4
5 Metropolis 2
Create a query called "ProvinceNames":
SELECT "Name" AS "Province"
FROM "Provinces"
ORDER BY "Province" ASC
Create a query called "Province of City":
SELECT "Provinces"."Name" AS "Province", "Cities"."Name" AS "City"
FROM "Cities", "Provinces" WHERE "Cities"."ProvinceID" = "Provinces"."ProvinceID"
ORDER BY "Province" ASC, "City" ASC
In the form, create a table control based on the query "ProvinceNames".
Using the Form Navigator (or the Form Wizard), create a subform for query "Province of City".
Right-click on subform and choose Properties. Under Data tab:
Link master fields "Province"
Link slave fields "Province"
Create a table control for the subform as well. Now, the cities shown in the subform control depend on the province selected in the main form control.
EDIT:
Here is an example using a filter table to store the current value of the list box. Create two more tables named "Users" and "FilterCriteria".
UserID Name ProvinceID CityID
~~~~~~ ~~~~~~~ ~~~~~~~~~~ ~~~~~~
0 Person1 1 2
1 Person2 2 0
RecordID ProvinceID CityID
~~~~~~~~ ~~~~~~~~~~ ~~~~~~
the only 0 0
We'll also need two Basic macros which can be stored in the document or in My Macros. Go to Tools -> Macros -> Organize Macros -> LibreOffice Basic.
Sub ReadProvince (oEvent as Object)
forms = ThisComponent.getDrawPage().getForms()
mainForm = forms.getByName("MainForm")
cityForm = forms.getByName("CityForm")
listboxProvince = mainForm.getByName("listboxProvince")
listboxCity = cityForm.getByName("listboxCity")
selectedItemID = listboxProvince.SelectedValue
If IsEmpty(selectedItemID) Then
selectedItemID = 0
End If
conn = mainForm.ActiveConnection
stmt = conn.createStatement()
strSQL = "UPDATE ""FilterCriteria"" SET ""ProvinceID"" = " & selectedItemID & _
"WHERE ""RecordID"" = 'the only'"
stmt.executeUpdate(strSQL)
listboxCity.refresh()
lCityCol = mainForm.findColumn("CityID")
currentCityID = mainForm.getInt(lCityCol)
cityForm.updateInt(cityForm.findColumn("CityID"), currentCityID)
listboxCity.refresh()
End Sub
Sub CityChanged (oEvent as Object)
listboxCity = oEvent.Source.Model
cityForm = listboxCity.getParent()
mainForm = cityForm.getParent().getByName("MainForm")
lCityCol = mainForm.findColumn("CityID")
selectedItemID = listboxCity.SelectedValue
If IsEmpty(selectedItemID) Then
selectedItemID = 0
End If
mainForm.updateInt(lCityCol, selectedItemID)
End Sub
Now we need to set up the form like this. In this example, I used two top-level forms instead of a subform. ProvinceID and CityID text boxes are not required but may be helpful in case something goes wrong.
To start creating this form, use the form wizard to create a new form and add all fields from the Users table.
Now, in the Form Navigator, create a form called "CityForm". Content type is SQL command, and Content is:
SELECT "RecordID", "ProvinceID", "CityID" FROM "FilterCriteria"
WHERE "RecordID" = 'the only'
Next, create the "listboxProvince" list box under MainForm. Data Field is "ProvinceID", and List content is the following Sql.
SELECT "Name", "ProvinceID" FROM "Provinces" ORDER BY "Name" ASC
Finally, create the "listboxCity" list box under CityForm. Data Field is "CityID", and List content is the following Sql.
SELECT "Name", "CityID" FROM "Cities" WHERE "ProvinceID" = (
SELECT "ProvinceID" FROM "FilterCriteria"
WHERE "RecordID" = 'the only')
Macros are linked under the Events tab of each control.
Assign "After record change" of the MainForm to ReadProvince().
Assign "Changed" of listboxProvince to ReadProvince().
Assign "Changed" of listboxCity control to CityChanged().
The result allows us to select the Province to filter the list of Cities. Provinces and Cities that are selected are saved in the Users table.
There is another approach which may be better that I have not had time to explore. Instead of the "FilterCriteria" table, apply a filter to the Cities list. The relevant code in ReadProvince() would look something like this.
cityForm.Filter = "ProvinceID=" & selectedItemID
cityForm.ApplyFilter = True
cityForm.reload()
cityForm.absolute(0)
Whatever approach is taken, a complete solution requires complex macro programming. To make it easier, you may decide to use a simpler solution that is not as powerful. For more information, there is a tutorial at https://forum.openoffice.org/en/forum/viewtopic.php?t=46470.
EDIT 2
A solution that requires fewer queries is at https://ask.libreoffice.org/en/question/143186/how-to-use-user-selected-value-from-combobox1-in-combobox2-select-statement/?answer=143231#post-id-143231. The second list box is based on a list of values instead of an SQL query.

How to split same record in Form Grid?

I need to split the same record two time.
For example, if I have in MyTable five record I need to show in Form's Grid ten record.
If It's possible I can create a View, I just to duplicate one time the same record.
This is my start point :
I want to duplicate the record :
In MyForm can't edit anything, is only View. No Delete, No Edit, No Create
Thanks in advance!
This sounds like an exercise, which we probably shouldn't be giving you the answer to...but try creating MyTableJoin and create a foreign key relation to MyTable.Id then add a field called MyTableJoin.Row and populate the table with 2 matching rows for every 1 row in MyTable. Then on your form, join MyTableJoin.
So:
MyTableJoin.clear();
MyTableJoin.Id = "ID_I";
MyTableJoin.Row = 1;
MyTableJoin.insert();
MyTableJoin.clear();
MyTableJoin.Id = "ID_I";
MyTableJoin.Row = 2;
MyTableJoin.insert();
MyTableJoin.clear();
MyTableJoin.Id = "ID_II";
MyTableJoin.Row = 1;
MyTableJoin.insert();
MyTableJoin.clear();
MyTableJoin.Id = "ID_II";
MyTableJoin.Row = 2;
MyTableJoin.insert();
You can create a union view and add same table twice. Just be shore to select union all option so that you do not get unique results.

How to search and display the fields from a table in an editor widget using progress 4gl

Accept a customer number and then output the details of each order and items to an editor widget.
Here customer , order ,order-line and items are table names.
where as customer and order tables have cust-num as common field , order and order-line(table-name) and order have order-num as common field , order-line and item have item-num as common field.
now i have to use a fill-in (f1 is object name) to get the cust-num and use a search button (search1 as object name) to find the corresponding fields and display them in the editor widget ( editor-1 as object name).
define temp-table ttcustomer
field custnum like customer.cust-num
field cname like customer.name
field orders like order.order-num
field items like item.item-num
field itemname like item.item-name .
find first customer WHERE customer.cust-num = input f1 NO-LOCK .
create ttcustomer .
assign
ttcustomer.custnum = customer.cust-num
ttcustomer.cname = customer.name.
for each order WHERE Order.cust-num = input f1 NO-LOCK .
assign
ttcustomer.orders = order.order-num.
for each order-line where order-line.order-num = order.order-num no-lock.
for each item where item.item-num = order-line.item-num no-lock.
assign
ttcustomer.items = item.item-num
ttcustomer.itemname = item.item-name.
end.
end.
end.
i have written this code in search button .
how can i display the temp-table ttcustomer in editor widget please help me :)
You'd probably be better off using a browser instead of an editor. But if you are going to use an editor, this should give you what you need:
DEFINE VARIABLE edData AS CHARACTER NO-UNDO.
FOR EACH ttcustomer:
edData = edData + ttcustomer.items + ", " + ttcustomer.itemname + CHR(10).
END.
editor-1:SCREEN-VALUE = edData.
The editor is just text so you won't be able to do any record selection/manipulation like you can with a browser. And if you have many ttcustomer records, you run the risk of overflowing the 32k character string size limit.

Crystal Report with multiple datasources, one is empty

I have a Crystal report with a table as a datasource and I want to include another table with details for the report footer.
I have two data sources in the report which are not linked, but when the selection criteria returns no rows from the main table, the results from the non-empty non-linked source are also empty.
I suspect it's doing a cross join between the two datasources, so if one is empty, that joined with another is also empty. The problem is I need my rows from the non-empty table to show in the report footer section, and they're getting suppressed by the other, empty datasource.
How can I get rows from an independent table to show in the report footer when the selection criteria and their parameter choices return an empty result set in the main table?
Thanks for your help,
-Beth
Also, I tried using a command as a datasource with sql like this:
select * from waitlist
union all
select distinct null as reportID, null as ..., lastupdated
from waitlist
but it still returns null for lastupdated and suppresses the subreport in the report footer.
I ended up setting my report datasource to a view which unioned another row to the table. I also needed to change my selection criteria so it allows this row to pass through.
Here's my datasource:
CREATE VIEW [dbo].[vw_rpt_waitlist] AS
select * from waitlist
union all
select distinct
reportID,
null as (fields...),
lastupdated,
'reserved' as countyName
from
waitlist
and here's my record selection formula:
({vw_rpt_waitlist.countyName} = {?County} or
{vw_rpt_waitlist.countyName} = "reserved") and
{vw_rpt_waitlist.reportID} = 14
I'm also suppressing the detail section if there were real rows returned:
formula = {vw_rpt_waitlist.countyName} = "reserved"
and to get the parameterized county name they selected in the page header of the report, I'm using:
dim t as string
dim c as string
if {vw_rpt_waitlist.countyName}="reserved" then
c = {?County}(1)
else
c = {vw_rpt_waitlist.countyName}
end if
t = "Waitlist by " + {#serviceTitle} + " and Waiver Need Index as of "
+ cstr({vw_rpt_waitlist.lastUpdated},"MM/dd/yyyy")
formula = t
Since the 'reserved' county always comes through, the subreports are not suppressed.

Drupal onChange auto populate another CCK select list

I have built a multistep form using CCK, however I have a couple of issues outstanding but, not sure if CCK can help.
In one step of the form I have 2 select boxes, the first is auto populated from the vocabulary table with the following code and all woks well.
$category_options = array();
$cat_res = db_query('select vid, name from vocabulary WHERE vid > 1 ORDER BY name ASC');
while ($cat_options = db_fetch_object($cat_res)) {
$category_options[$cat_options->vid] = $cat_options->name;
}
return $category_options;
What I would like to do is, when a user selects one item from the vocablulary list it auto populates another select box with terms from the term_data table. I have 2 issues;
1) I have added the following code to the second select list, just to make sure it works (IT DOESN'T). There a multiple terms associated with each vocabulary, but the second sql statemant only returns one result when it should return several, (SO SOMETHING WRONG HERE). For example in the term_date table there are 6 terms with the vid of 3, but I only get one added to select list.
$term_options = array();
$term_res = db_query('select vid, name from term_data WHERE vid = 3 ORDER BY name ASC'); while ($options = db_fetch_object($term_res)) {
$term_options[$options->vid] = $options->name;
}
return $term_options;
2) Can I add an onChange to the first select list to call a function to auto populate second list using CCK, or do I have to lean towards doing my entire form using the FORM API.
Any help or thoughts would be very much appreciated.
It seems to be a mistake in the query that gets terms. I tried to correct:
$term_res = db_query('select tid, name from term_data WHERE vid = 3 ORDER BY name ASC');
while ($options = db_fetch_object($term_res)) {
$term_options[$options->tid] = $options->name;
}
In your code you selected vid that is actually equal for all terms. Then you added terms names to $term_options array under the same key => so you got only 1 element.
Considering the second question: I would send the whole data structure (all vocabularies and their terms) as json to the client (insert a js script to the page from your drupal code) and implement the desired functionality with jquery.