Using selected values in a listbox
Posted on 2003-11-12
Sorry experts, this necessarily has a long explanation. Hopefully you'll find it interesting and worth reading! The points will reflect this ;-)
In a database I have a form called Form1 which I use to store data about chemicals. The database has lots of these forms with data in them. The form also has a radio button field called "Selected" which is by default "No" but the user can change to "Yes" if his factory uses that chemical.
I have a view called "Fluids in use" which filters out these forms that pass the condition Selected="Yes". Its first column is the name of the chemical described on the form.
In another form called Form2, I have a listbox field called Fluids whose formula is @Unique(@DbColumn("":"NoCache";"";"Fluids in use)";1)). So when the user creates a document with this Form2, it displays in the list box all the selected fluid names. All this bit works fine.
Now for the tricky bit. I've noticed that I can click the names in the listbox and a little tick appears by the ones I click. If I close the document and select it in a view and open the properties dialog box, I can see the contents of all the fields in the document, and when I look at the Fluids field it has in it all the names of the chemicals that I have ticked. If I didn't select any chemical by clicking it as described, then this field is empty (ie it shows "") in the dialog box. I can get this to do things for me, like hide fields in the form using a formula like @If(Fluids="") - if a fluid name is ticked, this formula returns false and vice versa.
What I'd now like to do now is to take this a bit further. I'd like to access data on the selected Form1 forms, from within the Form2, but only if their name has been selected in Form2 by clicking the box.
So, to recap:
1. We have lots of instances of Form1, most with Selected="No", some with Selected="Yes"
2. We have a single Form2, with a listbox field Fluids showing the names of fluids where the user has changed Selected to Yes
3. I have clicked several but not all of these fluid names in Form2 and they have a little tick by their name.
4. I want to read the value of another (number) field Field2 in all the Form1 documents that have been given a tick, but no others.
I'm then going to work on the data thus retrieved from the Form1 documents using existing code. This code presently works, but only for all the selected fluids, ie it doen't allow for whether the name is ticked in the listbox or not. It involves reading into a matrix the values of Field2 from all the documents in the "Fluids in use" view. So we need to repeat that but add on this new condition that the fluid names are ticked in the listbox.
Phew! Long one. I hope you made it to here and can help!!