One combo box for two queries Access - ms-access

I have a form that needs to use two combo boxes but the values in the second combo should come from two different tables based on the first combo selection. If I select option A in combo_1 I want to list all the agency names from tblRefAgency in combo_2. If I select option B in combo_1 I want to list all of the carriers from tblrefCarrier in combo_2. I can add VB code to hide/show two different combo boxes and then overlap them, but I feel I should be able to do this in a query. Thoughts?

As long as you are dealing with a single form, you can easily set the row source of the second combo in the After Update event of the first combo.
If Me.Combo1=1 Then
Me.combo2.RowSource = "SELECT ID, Description FROM tblRefAgency
End If
If the 2nd combo is bound to a field, you will also have to set the combo in the current event to ensure that data is displayed properly.

Related

Can I bind 3 comboboxes to one form?

Each of three columns: cust_id, cust_name, cust_company are in are in three combo boxes, each returning the cust_id as the key. When any of the combo boxes has a value chosen, I'd like to update a sub-form's data. I'm new to access, but my background is programming. I've yet to figure out where anything is beyond create wizards and property sheets, so be gentle.
Thanks!
Jimbus
Use three subforms:
Make the main form unbound
Place the three comboboxes to select cust_id on the main form
Place the tab control on the main form
Place a subform on each of the three pages of the tab control
On the main form, for each of the subforms, set these properties of the subform control that holds it:
LinkChildFields: The foreign key of the subform (cust_id)
LinkMasterFields: The combobox used to select cust_id for the subform
Zero code.

Clear out dropdown value once another drodown value is changed in vba access?

I have three combo box controls(MFG, Code, and GrpID) in my VBA access form. Once the user selects an option from the first combo box (MFG), rest of combo boxes give me available options. But I need to do some validation i.e. what if the user decided to change the value of first combo box? The values of rest combo box should be cleared. All I need to do is once the first combo box is changed the second and third combo box need to be cleared out or at least set to focus on them so that users will realize that they can't use old values as first value is cleared in the first combo box. I added a code block 'AfterUpdate for first combo box as shown below:
Private Sub MFG_AfterUpdate()
Code.Value = " "
GrpID.Value = 0
End Sub
The problem after writing above code is: they don't get empty until they(Code and GrpID) get clicked. In other words, I need to click them to empty them every time I change the value of MFG. Can anyone direct me how do I clear them or at least focus them?
Set the combo to null to wipe any displayed value in them;
Me.Code = Null
Me.GrpID = Null
This assumes your combo controls are called the same as your field names.
Edit for clarity: Including the Me. makes sure your are changing the form control values. If your field names are the same as the controls then Access will change the underlying field values, and as you have discovered on your form these aren't reflected until you click in that fields bound control.

MS Access: Why is my combo box displaying the wrong value?

I have 2 columns that populate my combo box. They come from a table where I manually wrote in an ID and a clean_value field.
The goal:
Display both columns on a combo box on a form. The ID values should be on the left of the clean_value values when looking at the drop down list. When selecting something in the list, the combo box should display the clean_value, not the ID. When saving the form, the form should write the ID value to a different table.
What I've tried:
I set up the table to get the values from. I set up the combo box to show the 2 values in the correct orientation. The ID value is the value that is being written to the table.
The problem: When the user selects one of the values in the list, their selection shows the ID. I want to display the clean_value upon selection instead. How do I do this?
I found a way to do this. I grabbed the clean_value field, the ID field, then the clean_value field again in the row source, then I just set the width of the first clean_value field to 0.021".

MS Access Multi-select Combo Box Select All/None

I have a combo box on a form that is linked to a SharePoint field, the combo box populates correctly however I am having difficulty trying to add VBA code to select all of the options or to unselect all options.
With a standard combo box you can use:
cmbBox1.value = ""
and that will reset the field. The same thing can be done with a list box that has multi-select enabled however this tosses an error, "This control is read-only and cannot be modified", with the combo box that has multi-select because of the lookup.
I have done some searching however no one seems to have a real answer other than to use a listbox instead and that isn't a solution here.
Has anyone worked with one of these fields and know how to select all of the options using VBA?
Here is a link describing this type of field but it does not discuss how to interact with it using VBA - http://office.microsoft.com/en-us/access-help/use-a-list-that-stores-multiple-values-HA010031117.aspx.
UPDATE:
There has been some confusion about the type of field I was describing so I have added some screen captures to show the difference between a combo box that allows multiselect, a list box that allows multiple options and a combo box with the option added.
First the field I was describing:
Second the list box:
Lastly the combobox:
These images visualize the issue that was described. As you can see there are multiple check boxes that need to be selected or unselected. Normally I would not create a field like this but as described above this is how Access interprets a combobox from SharePoint that allows for multiple selections.
After a ton of searching and trial and error I figured it out.
To unselect all of the check boxes it is
cmbBox1.Value = Array()
So with this information I figured that to select items they have to be in an array. Creating an array with all of the items that are in the combo box and then setting the combo box equal to the array will select all of the items.
I used a basic loop to set each element of the array
Dim SelVals(), i
ReDim SelVals(0 to cmbBox1.ListCount - 1)
For i = 0 to cmbBox1.ListCount - 1
SelVals(i) = cmbBox1.Column(1,i)
Next i
cmbBox1.Value = SelVals
Obviously then you aren't limited to only using the entire contents - you could assign any array and those would be the values selected.
http://msdn.microsoft.com/en-us/library/office/aa140084(v=office.10).aspx
I beleive this covers what you are asking

msacces 2010 how to create table with comboboxes in subtable from many related tables

I have the tables:
products, measures, colors
for each product I have related measures and colors.
Also I have a form with subtable where I need to show the table with columns:
[products] comboboxColumn, [measures] comboboxColumn and [colors] comboboxColumn.
The rows should be selected product, selected measure, selected color.
The question is:
how can I filter the measures ComboBox list for [measures] combobox-Cell (or colors ComboBox list) in my grid selected row, when I choosing a product from [products] combobox-Cell in that very selected row?
I suggest you use a continuous form rather than a datasheet. Create the combo and populate it with the relevant values in the current event and bind it to the correct field in your table. To avoid confusing the user, include a textbox bound to that field also. You can lock the textbox and label the combobox column something like "Choose Size". You can use conditional formatting to make the whole think prettier.