Access: insert multiselect box values into database - ms-access

I have a form setup in Access that contains many input fields and dropdown boxes.
This form doesnt contain an insert button. I just click on 'add record' at the bottom of the window.
Now I`ve add a multiselect box which contains multiple values.
I want the form to insert the selected values from the multiselect box along with all values from the other input fields in the same row if possible.
For example; the column that holds the multiselectbox values needs to contain 1,2,3
Another option is to store these values in a different table as long as I can join both tables when generating reports later on.
Any pointers are appreciated

You have two options. Either way requires a table structure like this (called a many-to-many relationship):
Option 1 is to make a subform which has a combobox on it. The subform is bound to this cross reference table ParentTableLookups and the combobox's control source is ParentTableLookups.LookupStoreValue and Rowsource is the Lookups table.
This is much less code and doesn't require a save button however it does mean that in order to see the things a user did not select they need to open the combobox. Maybe not quite as visually complete as the listbox.
Option 2 is to use the same table structure but instead of a subform you fill in a listbox on your parent form from Lookups. Then you iterate over ParentTableLookups where ParentTableLookups.ParentTableId = your current record and for each ParentTableLookups.LookupStoreValue you select that in the listbox.
In the parent form's AfterUpdate and AfterInsert records you need to repopulate ParentTableLookups based on the selected listbox values. You can create the records using DAO easily.

Related

Form to edit table selected from combobox

I have several (many, 30+) tables of values ready for use in comboboxes on various forms. I want users to be able to add values to these tables in case they need an additional value while filling out a form, but I do not want to create 30+ identical forms (one for each table) to make edits. So, I have a form where I can select one of the tables from a combobox and then open another continuous form that will eventually be used to show and edit the values in the table I selected. What I can't figure out is how to link the continuous form text fields to the table I selected in the previous form. I need to be able to set the textBox control source to something like [Tables]![[Forms]![FormToSelectWhichTableToEdit]![Combo0]]![DropdownValues], but I have the wrong syntax or something.

Binding Checkboxes to Specific Table Entries in Access

I have a small table of items that will not be changed. For each item entry in the table, there is a yes/no value that I want to bind to a checkbox in a form. The problem is, it seems like I can just bind to the column, not to specific entries in the table. How do I bind a checkbox to each item in the table?
I'm using Access 2010.
Set up your form using the 'Continuous Forms' option in the Form's format default view. You will see each record in the table with individual controls for each field.

Access: a Form with 2 subforms (Same table)

I am trying to create a Form of Payments, and I want to split the actives and pasives with two subforms.
I have made it, and works! The table Payments store the values.
The actives and pasives are in a table.
ID -> Number
Description -> String
Pasive -> True/false
I have created two Forms, for actives and pasives. Each form displays the corresponding values.
Also I have created main Form that contains two subforms (actives and pasives)
When I insert a Payment
GREAT! It works!
But, when I open again the form, the values are disordered.
Can you help me?
Thanks!
I'm not sure if it understand you correctly. It looks like your subforms don't know which data is passive and which is active. Try this:
Instead of yes/no field in your table, you could rather create field with dropdown list that allows you to pick one of two values: passive or active. Let's name that field: transactionType.
Then you should add transactionType control to each subform.
In the first subform you set default value for transactionType control as a ="active", in the second subform: ="passive".
Now you can set visible parameter of transactionType controls in both subforms to no. In form view you won't see them, but if you create new record, the will add proper information to your table.
Are your subforms based on query? If no, go to subforms data source, create query based on your table and in the criteria of transactionType field set respectively "active" (in the firs subform) and "passive" (in the second one).
When you reopen
your form, thanks to query filter you have set in step 5, subforms will
display only actives or only passives. If you chose that solution, this will work for new data only. If you already have some data in your table, you should manually complete trasactionType for each existing record.

MS-Access unbound ComboBox in DataSheet?

In ms-access 2007, i'm trying to make a form for a table. this table has foreign keys from 2 parent tables. so i thought i would make these fields a lookup. but i couldn't create a single lookup for each parent table because they are composite keys.
I decided to create a query in which for each of these parent tables and the child table with an extra field for each composite key. this works fine with a normal form using an unbound ComboBox... but the unbound ComboBox does not work in a DataSheet Subform. when i make changes to a ComboBox in the Subform code, they are applied to all the other ComboBoxes in the same column as well.
My questions:
is there a way to change the values of the individual unbound ComboBox?
is there a different control i should be using other than the ComboBox or the DataSheet Subform?
what is the normal work around for this situation?
I cannot bind the ComboBox's because the field from the query is calculated/an-expression as I said.
I ran across a form of this problem myself, so for the sake of posterity:
While generally, the advice "Don't use continuous forms/datasheets in this situtation" is the best advice...It is possible to work around this.
However, access will not let you update the value of a single control on a datasheet. What can be used instead in this case is a temporary table, which can, when used as a recordsource, become the values of those controls. You will need to repopulate the table, and requery the controls (requerying the entire form should work as well) every time the calculation needs to change, however. Furthermore, should you enable editing on the controls, you will have to write some VBA on each control to handle the update event (Before Update), and run your own query to update the source tables, not merely the temporary table. Annoying to do perhaps, but effective.
There is another possibillity, which may also work, but I haven't tried to do something quite like this myself. The rowsource of a combobox can be very complex, so it is probable that you do not need to update the comboboxes with VBA at all. The rowsource can depend on other controls (such as another combobox) using the syntax Me.Form!controlName or Forms!FormName!ControlName, which will allow you to form the composite key. Of course, you can also select from queries with a rowsource. What is more interesting is that queries can reference controls on your form, provided the form is open, and you should safely be able to modify that with VBA should you have to.
Between the two of these, you should be able to force access, kicking and screaming, to display any data you wish, even on a datasheet, and to allow the user to change that data (but only if you want it to), and using the BeforeUpdate event, drag modified data back to whatever table it came from.
Continuous forms and datasheets do not work well for editing in situations where combo boxes need to be changed conditionally. The problem is that if you use the OnCurrent event to set the Rowsource of the combo box, it will be OK for that row, but will then hide the stored values for other rows.
The solution is to never use continuous forms/datasheets for editing data when this is the case (I hardly ever use them for editing, in fact). You can create two subforms, a continuous/datasheet subform that functions as a list, and a detail subform, that displays one record. Make the list subform uneditable, and the detail subform editable. You can link the two of them by using the Link Child/Link Master property of the detail subform control, and set it to the PK of the list subform.
If your list subform is Me!List and your detail is Me!Form, and the PK field is MyID, your link properties for the detail subform would be:
Master: Me!List.Form!MyID
Child: MyID
When you move to a different record in the list form, it will be automatically loaded in the child form. Any edits to the previously displayed detail will be saved before record departure.

How can I create a Multiple Value Combo box on an Unbound Form

I need your help on MS Access 2007.
I have a big problem with my MS Access Unbound Form.
How can I create a combo box i do not want bound to a table, show a multiple value List?
The Combo is named Sector and want these values to be selected in Multiples 9Which should be possible in Access 2007) from the Drop Down List: Fertilizer, Seeds, Pesticides, Veterinary products, Animal Feed, General.
Which Select Statement or VBA code can I use. I need a solution to handle this please.
Precisely a ListBox control will help you. Since you are using it in MS Access - it makes it much easier with the wizard where you can type the items list. Or if you want to use VBA, then you can load the list using AddItem property of ListBox control in the Form_Load event.
Here is one way of doing what you want:
Open up the table your Form will use. Then: Datasheet view, Datasheet Tab, Lookup Column. Select option: I will type in ... Next Under Col1 enter one of the user choices you want; for example
A Dogs, then under that enter another choice; for example B Cats, etc Next give your lookup column label a name or stay with the default. Finally, Check Allow Multiple Values box. Finish.
You now have a table with a combo box that allows the user to select 0, 1 or many choices.
But you want it on a Form.
Create Tab, Click Form. You now have a Form that has a multi value combobox.
But you want it on a form you already created.
Right click the ComboBox. Copy. Close the table and open the form you want the ComboBox to be a part of.
Right click on a clean part of the form and Paste.
Hope this is what you were looking for.