Full Version: Invoking a Form action based on a Combo Box list selection
UtterAccess Forums > Microsoft® Access > Access Forms
melikka
I am wondering if anyone can help me with a question regarding using a combo box on a form. I have a combo box and I want another form (pop up form asking for more information) to open when a certain item in the combo box list is selected. Can anyone give me a tip on how to program this? Thanks...
GroverParkGeorge
Welcome to the Utter Access Forums
On the After Update event of the combo box put the following:
If me.cboYourComboBox = TheValuethatTriggerstheRequest Then Docmd.OpenForm "frmInformationRequestForm"
Change my names to the ones in your database.
George
melikka
Thanks so much...that was exactly what I needed and it worked perfectly!
melikka
In regards to this same question....now that I'm able to get the pop up form to open when I want it to, how would I now link the two forms together so that what I enter on the pop up form gets input on the same record as the original form with the combo box (these forms are both linked to the same table). I am using a field called "ID" to link my forms together. Thanks...
GroverParkGeorge
You can use OpenArgs to pass the value from one form to the other, and filter the second form with that value.
If me.cboYourComboBox = TheValuethatTriggerstheRequest Then Docmd.OpenForm "frmInformationRequestForm"", , , , , , Me.cboYourComboBox
In the Open event of frmInformationRequestForm, put the following
Me.Filter= "ID = " & Me.OpenArgs
Me.FilterOn = True
This will filter the recordset for the information request form to the value of the combo box passed through OpenArgs.
Any edits, or additions you make in frmInformationRequestForm will be part of the same record.
BTW: I suggest you chose a more useful and meaningful name than "ID" for the primary key. It's so generic that confusion is almost certain at some point.
HTH
George
melikka
Thank you for the replies to my previous posts...you have really helped me alot. I am just learning so, I can use all the help that I can get! frown.gif
I was wondering if you could help me with this problem I'm having as well? I have 2 unbound list boxes with arrow command buttons in between them so that the user can move one or multiple selections from the "ChooseList" list box into the "ChosenList" list box. I've got all of that working okay but what I would now like to do is to be able to display the values from the "Chosenlist" list box in a field on the form called "txtOtherAcceptables". How would I do this?
Thanks again so much for your help!
Melissa
P.S. The list boxes and text box are all on the same form called "frmOtherAcceptables" and each list box is only one column.
GroverParkGeorge
Well, there are probably a couple of ways to go about that, but I'm wondering why you need to do it. Isn't the list already displayed in the list box? What's the value of having a second control to display the same information?
melikka
So, just have the list box put all of the selected choices into the respective "OtherAcceptable" field in my table? How do I do that? The bottom line is that I've figured out how to get the control to work selecting the data and moving it around but I don't know how to put the multiple list choices into the field in my table where I ultimately need it (this is the first time that I've worked with putting multiple list selections into one table field so that is what is hanging me up). I see your point though...and, yes, if I can just use the list box for both the selection and display that would be great.
Thanks again...
Melissa
GroverParkGeorge
Actually, if your goal is to put all of those list items into one field in a table, then you have a different, and more serious, problem. It is not appropriate to store multiple values in a single field. If you have a one-to-many relationship with these "Other Acceptable" values, you need a separate table for these list items.
George
melikka
Okay...thanks. I was hoping that there was a way around having to set up another table but, I will take that approach now.
Thanks again for your help...
Melissa
ace
To answer your question about how to get the values from a multi-select listbox,
lookup --> ItemsSelected Property <-- in the VBA help file. The example code
shown there will be very useful.
You get to the VBA help file from the VBA IDE,
not from the Database Window.
GroverParkGeorge
This really gets down to the heart of what a "relational" database is, and how it is most useful and effective. Frankly, it is POSSIBLE to lump all of the values together into a field, but that is hardly useful in the long run.
Let's say that you have a dozen records, and that you have clumped 4, or 5, or 6, or more DIFFERENT COMBINATIONS of "Additional Information" items into a single field in each record. Later, you want to go back and do a search for records where any one of those "Additional Information" items exists. Writing a query to do that is difficult and inefficient. A query to find COMBINATIONS of "Additional Information" becomes even more diffifult. True, it CAN be done. However, the whole point of creating a relational database is to avoid that sort of difficulty by organizing data efficiently. And that means a related table with a one-to-many relationship.
HTH
George
ace
> This really gets down to the heart of what a "relational" database is, and how it is most useful and effective.
agree 100% that there is a problem with the op's data structure.
That said, if they want to run with their idea for a UI (the multi-select listbox) they will
still need to know how to retrieve the selected values from the listbox and add them to
the related many side table.
GroverParkGeorge
Thanks, good point.
melikka
Thanks for the input. I used your suggestion creating a separate table and also the info on how to retrieve the selected values from the listbox and it's working great. Really appreciate your 2 inputs. frown.gif
elissa
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.