Change default values of controls with button click

buratti

Registered User.
Local time
Today, 17:05
Joined
Jul 8, 2009
Messages
234
I have an unbound form which displays several combo boxes. The combo boxes display a list of employees. Each combo box has an associated subform where on the onLoad of the form and also after update of the combo box, the associated subform's record source changes to reflect the selected employee. Everything is working just fine right now. In the properties of the form I have the default value of each combo box set to a different employee. I want to add a button to the form so the user can change the default values of the combo boxes, so the next time they open the form the employees are rearranged in the order they selected as the new default. For example...

Right now the combo boxes are layed out in a row and default values set as follows:

Employee1 Employee2 Employee3...

Lets say the user changes the combo boxes to the following:

Employee3 Employee1 Employee7 Employee5...

I want to add a button that saves the current "layout"/values of the combo boxes as the new default values, so the next time they open the form it displays Employee3,1,7,5... and not the original Employee1,2,3,4...

A thought I had (which I dont know it would work or even the right way to do it) is OnOpen of the form hard code the default values of each combo box (instead of setting them, in the properties window), then in the onClick of the button write code that changes the hard coded values in the OnOpen event to the current values. Theoretically this would work, but I have never written code that changes code and dont know how to do so. Any help or other suggestions???
 
Create a table, bind the combos to that table by setting the recordsource of the form, and setting the control source of each combo. Then if a user makes a change the change is persisted to the table. Maybe this table only ever has one record, fine.
But the idea of writing code to rewrite code as a solution to a data storage and retrieval problem seems to me to miss the target by quite a lot.
Cheers,
Mark
 
I dont know if I completely understood your answer, so let me rewrite it in what I interpreted it as...
Well first of all my combos are not "bound" to any control source but the do get values from my employees table. But anyway, so I would create a table with 7 fields (one for each combo on my form) and bind each combo to its own field, also setting the recordsource of the previously unbound form now to this new table. Yes this table would only ever have 1 record. From what I am understanding, I would then not need to set the default values of the combos in the properties sheet because they would get their initial values from the new table (only ever viewing the 1st and only record from that table).

I understand up to here, but if a user changes a combo value (just temporarally and not wanting to set it as default next time the form is opened) then closes the form, the bound field would be changed to the newly selected value and this new value will now be the default value displaying the next time the for is opened. Would it not?

Well actually as writing this a way around this is, I thought I could just attach some kind of undo command on close of the form to remove any changes to the table, and only save changes if the button was clicked. But is this roughly what you were talking about???
 
This is always an issue with data...
but if a user changes a combo value (just temporarally and not wanting to set it as default next time the form is opened)
...and only save changes if the button was clicked.
...that at some point you need to let your user make this decision, to make a change and keep it.
What I don't get though, is why you'd have, what, seven combos on the same form that all display data drawn from the same table. What kind of work gets done at this interface? Maybe a worthwhile conversation is to back up and understand what you are trying to do with this configuration. Like, why seven and not nine?
Cheers,
Mark
 
Well the 7 combo boxes are basically just for a certain visual affect I am trying to achieve. You see a while back I posted in these same forums about how display my data in a certain (unusual) format, and the only suggestion that seemed to work is have the 7 combos with 7 related subforms (or 8 or 9..., but 7 is the max number that will fit on a printed sheet of paper). If you are more interested or possibly have a better solution I can supply more info on why and possibly a copy of my DB, but please let me know... As for now, it sounds like what I am doing is bad design skills, but in reality it is the only way I can think of (even with help here) where I can display the data in the means I want.
 

Users who are viewing this thread

Back
Top Bottom