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

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".

Related

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.

Autofilling my form in Access with the use of a Combo Box

I'm having a problem when I want to autofill my form in Microsoft Access. The idea is that I use a combo box to select a name. Then the onChange code of my Combobox automaticlly inserts all the other data in the proper field. I use this code on the Combo Box.
Private Sub cmbName_Change()
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(2)
Me.tbBirthday = Me.cmbName.Column(3)
End Sub
This methode works fine for the personalnumber and the emailadress. But it doesn't work for the birthday date, it returns a null value but when I check my table there is is a date in the proper field.
Am I missing something? I tried everything but it wont work.
I was thinking that the problem is related to the birthday column being the last in the table. Or having the date type.
Thank you in advance for your time and efford!
Edit; The .Column(1) is missing because this is the name that is already inserted with the ComboBox.
There is some confusion caused by the wording of the question, I'll try to state back how I've interpreted and if I have it right it may lead you to an answer.
You have combo box called cmdName that is pre-populated with data from a table. The content of the combo box could look as below (you may have set column widths to zero to hide the data)
0001|Gary Evans|gary#email.com|01/Jan/1970
0002|J Rommers |JR#email.com |02/Jan/1970
When the user selects J Rommers Me.tbPersonalNumber is populated with Me.cmbName.Column(0) (0002) and Me.tbEmailadress is populated with Me.cmbName.Column(2) (JR#email.com) but Me.tbBirthday is not being populated with Me.cmbName.Column(3) (02/Jan/1970).
Assuming Me.tbBirthday is a text box with no code that might clear it out, I suspect the issue is within the combo box. Not being sure how your combo box is set up, I would suggets the following checks:-
In the combo box properties, does the Column Count equal 4?
In debug, with a breakpoint on Me.tbBirthday = Me.cmbName.Column(3), does it show you the date you are after?
If it is not there does the query that populates the combo box have it in?
Edit based on comments to help further: -
Change the query to SELECT Personel.PersonalNumber, Personel.Emailadress, Personel.Birthday, Personel.Name FROM Personel ORDER BY Personel.Name; this puts all the fields you want hidden at the front.
Change the column widths property of cmbName to 0,0,0, this first the ones you want hidden and leave the last one to fill the width of the combo box.
Ensure the column count property is still 4 as per the answer
Change your code as per below and Gustav's answer
Replacement code:-
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(1)
Me.tbBirthday = DateValue(Me.cmbName.Column(2))
This accounts for the fields moving in the query and ensure the date shows as a date like you wanted.
Comboboxes (and Listboxes) always return a string, so convert that to a Date value:
Me!tbBirthday.Value = DateValue(Me!cmbName.Column(3))

MS ACCESS Multiple Record Visibility If Statement

I am building a form in Access 2013 and I will print out 4 fields for each record.
So Let's say the form processes 2 records it will print out:
Field 1 Field 2 Field 3 Field 4
Field 1 Field 2 Field 3 Field 4
Now I want to have it when it displays Other to print out the description of the other from a table. To do this I want the field named DefectType to go invisible and then the Other field to become visible. I start with Other being invisible and DefectType Visible and place them on top of each other. Here is the VBA:
If DefectType <> "Other" Then
DefectType.Visible = True
Other.Visible = False
Else
DefectType.Visible = False
Other.Visible = True
End If
It works fine if they are all other because what it does it takes the first record value of Other and applies it to all the other records for that field.
So if the first record that is displayed has a field 3 and it has a value of Other it will then look for the value in the table that is under the "other" field and display the content. SO lets say the "other" content was lamination. Instead of showing Other it will make that DefectType field invisible and show the "Other" field which will show Lamination.
The problem is it then does this for the rest of the records. It won't test to see if the field 3 is "Other" or not, it will just assume and then put it's "Other" field contents for the subsequent records. This means that since some actually already have values in them, like Corrosion, and nothing in the "other" field it will display a blank box.
I want it to test each field 3 as it is displayed so it can tell if "other" is in the field or not.
I'm unsure how well I understand your question, but it sounds to me that your form includes 2 text boxes named DefectType and Other. When the value of DefectType is "Other", you want to display the value from the Other text box. But when the value of DefectType is anything else, you want to display the value of DefectType.
If that is correct, you can create a new text box named txtSummary and use this as its Control Source property.
=IIf([DefectType] = "Other", [Other], [DefectType])
The txtSummary text box would not be editable. To change its value, you would change the values in DefectType and/or Other.
That approach will ensure txtSummary is always updated based on the current values of DefectType and Other in the same record. And it will do that for each record in the form, including when the form is in Continuous Form or DataSheet View.
Your original approach would do what I think you want only when the form is in Single Form view.

One combo box for two queries 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.

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.