PDA

View Full Version : Anyway to have default text in a combo box?



Action82
01-30-2009, 10:48 AM
I have a field that I'm setting as a combo box with the row source type as value list with several choices. One of the choices will be the selection for about 90% of the time, so I was wondering if there is anyway to have it as the default text.

I've tried setting the default value in the table design and in the field properties of the form, but still nothing shows up.

Also, if I wanted to do something similar to this, but instead of using value list, I want to use another table so I can add to that table with new choices, but still with one choice that would be 90% of the time. Is this also doable?

Thanks for your input!

CreganTur
01-30-2009, 10:57 AM
Open your Form in design view and select your combobox control. Open your properties sheet and click on the Data tab. There is a property called Default Value- that's where you enter your default value for your combobox.

Action82
01-30-2009, 11:36 AM
I've tried that but it doesn't work. The field still shows up blank. I've tried putting in the text in the Default Value with and without quotes and still nothing.

What else could be wrong?

CreganTur
01-30-2009, 11:51 AM
Please post an example database that duplicates this problem. You can post your original database if you want, just be sure that there is no sensitive information within it. Also if there are multiple forms, tell us which one to look at.

Please post a 2000 or 2003 compatable database- you'll need to .zip it in order to upload it (available in Advanced posting).

Action82
01-30-2009, 01:10 PM
So I think I narrowed down the problem. Putting the text I want to show up in the default value only works if you add a new record at that same form. My current database is setup so that premlinary data is entered by an entry level associate and then a higher level associate intreprets some of that preliminary data and fills in another form.

Attached is a sample I created. If you create a new record in Form 1, the Choice cbo will default to what I set in the properties box. However, if you create a new record in Form 2, close out of it, and then open Form 1 and locate that record, the Choice cbo will not have the default value I want.

Thanks again for your help!

CreganTur
01-30-2009, 01:33 PM
The reason your default value isn't showing up is because the combobox is bound to your table. This means that it will always show what is in your table.

When you create a new record in Form2, you never set a value to the choice field, so it is blank. For this reason, the combobox is blank on Form1.

You need to set the default value in your table. Open your table in design view, select the Choice field, and look for the Default Value property.

HTH:thumb

Action82
01-30-2009, 02:04 PM
That did the trick! Ok, so here's another question that builds on the last one. I wanted to do something similar but the row source is linked to another table where there are two fields, an autonumber, and a choice. Is there anyway to have the default value of the cbo set to the highest autonumber? ie. everytime a new choice becomes available, it would be used most of the time so it should be the default, but there are cases where some of the older choices can be selected as well.

Is this even possible?

Thanks again for all of your help!

CreganTur
01-30-2009, 02:34 PM
Is there anyway to have the default value of the cbo set to the highest autonumber? ie. everytime a new choice becomes available, it would be used most of the time so it should be the default, but there are cases where some of the older choices can be selected as well.


Yes, it is very possible and very easy to do this. Here's some VBA code- you'll need to figure out which event you want to trigger it.


Me.combobox.DefaultValue = DMax("FieldName", "TableName")

Replace combobox with the name of your combobox, FieldName with the name of the field that houses the value you're looking for, and TableName with the table's name.

HTH:thumb

Action82
01-30-2009, 03:28 PM
I can't seem to find where I should place that code. Is it one of the fields in the Event tab?

CreganTur
02-03-2009, 06:20 AM
I can't seem to find where I should place that code. Is it one of the fields in the Event tab?

Yes, you're going to want it to be triggered by an event- you just need to test a few and see which one works best for you. Perhaps the comboboxes click or got focus event.

Test it and see what works for you.