How to implement multi-select? - ms-access

First of all, I need to say that I never worked with Access or any other databases before. I'm trying to understand how it works and picked "Students" template for this task (see step 0). Now, let's start.
i. Creating the base from the template and fill it with data
Step 0. Creating new database based on "Students" template:
Step 1. On the objects pane (i.e. left sidebar) search for Student List form and double-click on it:
Fill the First Name and Last Name for the first student: it will be Mike Smith.
In the Special Circumstances column it is possible to select multiple circumstances: for example, Circumstance 1 and Circumstance 2. And if you click on the icon below the combo-box, it is possible to edit the list of available check-boxes:
Step 2. After we have created the entry for the first student, double-click on the Guardian List form and create entries for 3 guardians: Jane Roe, John Doe and Jill Joe.
Step 3. Return to the Student List form. Click on the Open cell in front of Mike Smith. It will be opened Student details form for this student. When it will be opened, click on Guardian Information tab - and you will see, that all 3 guardians are available for combo-box:
ii. Now, my task
I want to see the guardians directly in the Student List form - the same way as Special Circumstances located.
I want to get the option to select multiple guardians for each student - the same way as Special Circumstances check-boxes are implemented.
iii. How it was solved myself, but only the 1st point of the task
To simplify the task, I will use Student ID column (located on the Student List form), instead of creating new column.
On the left sidebar - click on Student List form with right mouse button and then select Design View. When Design View will be opened, select Student ID field, right click on it, then click Change To and Combo Box:
Then, on the right sidebar select Data tab, set curson inside Row Source field and then click small ellipsis (...). In the Show Table window select Guardians and then click Add button and close this small window.
Then, in the large window, do this:
And then click Save As and Close on the ribbon.
Then, switch the Student List form back to the Layout view (the same way, as we switched it early to Design View). And you will see that the first point of my task is solved: the last names of guardians are available in Student ID column:
But how I can implement multiselect, the same way as it is implemented in Special Circumstances column? So, Mike could have both Jane Roe and John Doe as his guardians.

Multi-valued combo boxes are very odd controls. Avoid them whenever possible.
Creating an unbound multi-valued combo box is not possible (see How can I create a Multiple Value Combo box on an Unbound Form). A combo box is multi-valued when the field it is bound to is multi-valued, or when it's set to a multi-valued lookup.
To change a field to a multi-valued field, you need to alter the table design, and set the Allow multiple values property to Yes:
This will automatically change any combo boxes bound to this field to multi-valued combo boxes.
Note that I highly recommend not using this approach. This database already demonstrates a junction table, the recommended way to manage many-to-many relationships. Using junction tables and multi-valued combo boxes is not possible without using very hacky techniques.

Related

Access query combo box source based on individual record

my database has MachineT, ProductT and ProductionT.
each product can be made only in some specific machines (multivalue field).
when planning production I need the dropdown menu to show only the possible machines for that product in a form containing a datasheet view.
In the actual database the ProductionF has a data picker and the subform is based on ProductionQ only for that day and it is important to keep the datasheet view because the planner is adding dozens of records in one sitting.
thank you
*edit - I tried to force the field in ProductionT via lookup but it does not filter for each record.
[If you only have 4 machines], what if in ProductT, rather than just one Machine ID, you have fields M1,M2,M3,M4 as a Yes/No (checkbox) selection, then you can make your combo box where fields = True
or maybe this link can help you http://allenbrowne.com/func-concat.html
Edit
What if you have a new table called something like "Product_machine_combo" and this is where you can combine the relationship between the product and the machine used. You could use a list box that lists the Products and have a ListBox for the machines (kind of shown below; link to this resource: https://www.iaccessworld.com/add-items-textbox-listbox/). I just don't know how it would show up in the table. Or you could add a list box to the product form itself?

How to display all data in field (combobox) on form when rowsource of combo box does not include this value

Data previously entered into field not displayed when field on form is a combobox control
Have a form that displays information about an event. It includes the name of the staff member who initially set it up. The Combo box rowsource for this control is a list of current staff members only. If the original staff member who set up event has left (ie not current) the control shows a blank when form is opened on that record.
I want to know how to display historical (ie any/all data) but if user wants to change anything they only get the current (ie updated) list available to them.
The control stores the staff ID, the combo box displays the staff name (linked from the staff table. So when try to change the options it says I can't as the bound column is hidden.
You don’t have a lot of great choices here.
You of course cannot delete such records since as you point out, such history data will thus break.
There are a few suggestions I can think of.
First up, add the “active” staff column to the combo box display. Then if a user changes or chooses from the combo box, you can prevent (or warn) that they are selecting a non existing staff member. This would display non active staff, but would in theory allow users to select in-active staff – you might not want this. (but you could warn, or prevent in the control before update if you want to prevent this).
Another way is to dynamic load the combo box based on the current record. In other words, if the form is in say “add mode”, or the combo box is blank, then you load up the combo box with a select statement that only includes StaffActive = True.
The above can work rather well if you limit your “main” form to one record (I tend to do this). I tend to present a search form and THEN always launch the main form to ONE record.
So in the forms on-load event, you could check if the column id of the staff is set, and if not active, then you load up the combo box with all staff.
If the column has a staff memember that is active, then in the form on-load, you set the sql of the combo box to only active members.
This approach is “tricky” if you allow record navigation. In that case, you have to put the testing in the on-current event, and set the sql of the combo box that way. Hopefully the staff list table is “small”.
The 3rd way to fill a combo box is by using call backs. This is a LITTLE known approach, and again with on-current event, you could test for the id being a non active and thus set a vatriable (likely global) that allows the call back code to include non active staff.
However, if you stored “id” in that column of a staff record that no longer exists, then there is not a lot you can do. (I would perhaps attempt to re-enter the deleted staff with the correct id’s).
So it not clear if the staff record is deleted, or you have some “active” flag. If you have an active flag, then you can “test” if the staff “id” from the combo box is a non active staff, and then shove the correct sql into the combo box data source that includes the non active staff.
I suppose for performance reasons, and some reduced “flicker”, then I would perhaps set/track what the current combo box is displaying, and ONLY update the combo box if the status (non active) members are required.

Add new Items in a combo box in access

im new to access 2007
I have 3 tables and One Form..i have Accounts,IT and Software tables..i have created each table and enter a values for them(ID,Description).. i have another table called Faculty which i have the AccountsID,AccountsDesc,ITDesc and SoftwareDesc as attributes in my combo box form.So when i did my Query all working fine.even if Accounts Desc start with first character as 'F' it able to pick it up..because Finance was already entered in my database..My Question i want to add a new Accounts Name on the combo box without add from the database?..so that it can be saved in my drop down list if its selected again.. i try many ways but i cant..anyone can solve my problems?..
You can only have your combo list come automatically from a table, or by entering it manually into a value list. You can't do both.
So, to solve your problem, you'll have to use VBA. I'm just going to give you the rough steps here. You'll be ale to search for details if you don't know how to do a step.
In the Form_Load event, you'll build your list.
You'll do this by opening the table or query that has the values you want in your list, reading it one record at a time, and entering the value into your combo box.
The command for adding an item to the combobox is ComboboxName.AddItem value.
Then add your additional value you want. ComboboxName.AddItem "New Account"
Good luck

Can I make one form to get record data from multiple (unrelated) tables in Access?

I know only the basics of Access, so I am having trouble figuring out how to make a form that will access multiple unrelated tables.
My problem:
I have several tables which describe different card collections. There is no way that I want to link them, even if I could, e.g. by card names. This is because I want to keep the listings separate. I do, however, want to create one form that will access them all, so that I don't need to fiddle about clicking on different forms every time I want to update a card database. The more tables I include, the less practical this would get, anyway. I've tried looking this up and there are several sites which seem to suggest sql-like statements as solutions, but frankly these fly over my head - I don't even know where I'd write them!
So what I want is one form that has a combo box menu to select the table that I want to edit, then another box to select the card that I want to see and hey presto I can edit the details of that card. I can do this if I make one form for one table, but I don't know how to do it for many tables. I would also like it to check for new tables should I add them in. E.g. cards have different series that come out, so when a new one comes out I will create a new table for it, add the cards and so on...
I realise this is probably quite fiddly, especially in Access, but if anyone can give me some guidelines on how to do this it would be much appreciated. (I'm using Access 2007)
To answer your question:
Use subforms. Create few subforms and your combobox and hide/show the forms as you desire.
Better way to do it:
Creating separate tables for each card type is quite a bad practice. If the cards share features like MonsterName, MonsterPowerType or whatever, you should create another table like card_types and add a card_type field to the cards table. Then if you need to get only Pokemon cards create query with card_type_id = xx or card_type_name = "Pokemon" criterias.
This way you only need one form and you can change the card_type criteria with use of your combobox.
This is quite old, but it might help others. I did figure a way to do exactly what you asked
I only have access 2016, so things might be in a different place, but not that much.
First, create all the tables for each of your decks. Make sure you have in the first column : unique ID, second column the name of the deck (it's going to be the same for each entry in this deck) this is going to help us. The third column the name of the card. The other columns will contain your other values of your card, but for my example it doesn't matter.
I'll name them like this
column name
1 unique_ID
2 DeckName
3 CardName
Now, in the tab "create" choose "Query Design". Then in the tab "home" in the seciton Views, choose SQL.
in the blanck section enter this
I have 2 tables :
Table1 and Table2
SELECT Table1.DeckName FROM Table1 UNION SELECT
Table2.DeckName FROM Table2;
You have to add each table and add a UNION between each. You finish the sentence with one semi coma only ;
Click run and you should get all the DeckName.
Save your query and close it.
Now, we want the combobox to help us choose between the different decks.
in the tab "Create" choose "Blank Form". Go to "home/views" choose "design". In the "design" tab, choose the combobox. You can click cancel and skip the wizard
In the property, click "rowsource" and select the query you have created.
Name it Cmb_Deck
Add a second combobox
Name it Cmb_Name . property "Column Count" put "2" because this combobox will show the name of the card, which is column2 in our tables.To be a little bit fancy, we will hide the first column, in the property "Column Widths" put "0";1"" (first column 0inch, second column 1inch).
Drag any of the table you have create into the form and click cancel when the wizard appear.
Name it TableResult
Now that the layout is created, we need to change the table according to the combobox Cmb_Deck.
In the Cmb_Deck property go in the event section and choose "After Update" click on the "..." and choose Code Builder
In this Visual Basic editor window : delete everything that is there and enter this
Option Compare Database
Private Sub Cmb_Deck_AfterUpdate()
TableResult.SourceObject = "Table." & Cmb_Deck.Value
Cmb_Name.RowSource = "Table." & Cmb_Deck.Value
End Sub
Private Sub Cmb_Name_AfterUpdate()
Me.TableResult.Form.Filter = "([" & Cmb_Deck.Value & "]." & "[CardName]=""" & Cmb_Name.text & """)"
Me.TableResult.Form.FilterOn = True
End Sub
Now back in access, select your combobox Cmb_Name and go into property event/afterupdate and choose "[Event Procedure]
Now in your form, go to home/views and choose Form Views. First choose a deck in the first combobox, then choose the name of a card in the second combobox. Now the table underneath, shows only the card that you want to see.
I hope this helps
-Mathieu Paquin

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.