Default Value for Comb Box

G

Guest

Hi there,

My comb box's data source is based on a query. so, How can I make one of the
query result as a default in the comb box. Thank you very much!

clara
 
M

Marshall Barton

clara said:
My comb box's data source is based on a query. so, How can I make one of the
query result as a default in the comb box. Thank you very much!


Set the combo box's DefaultValue property to the desired
value.

That's probably not what you were asking for, but more
details are needed before making a more intelligent guess.

What do you mean by "default"?

Which row in the query has the desired value?

How is the combo box used?

Should this only be done for a new record? Or, is the combo
box is unbound?
 
G

Guest

I would like one the comb box item be selected when the form is open, the
selected item could be anywhere within the potential items. I tried to use
the defaultvalue property, but the #name? appeared. In my form, there are
five comboxes and each one match to a different data sources( table or query)

clara


thank you so much for your help
 
M

Marshall Barton

If the combo box's are UNBOUND (i.e. nothing in their
Control Source property) and you don't care which item is
selected, then the first item in the list is just as good as
any other. The line in the form's Load event procedure
would be like"

Me.combobox = Me.combobox.ItemDate(0)
 
G

Guest

Hi Marshall,

It works and it is what I need, but I am still confused about control source
and bound column. Could you give me a brief introduction plus an example

Thank you so much

clara
--
thank you so much for your help


Marshall Barton said:
If the combo box's are UNBOUND (i.e. nothing in their
Control Source property) and you don't care which item is
selected, then the first item in the list is just as good as
any other. The line in the form's Load event procedure
would be like"

Me.combobox = Me.combobox.ItemDate(0)
--
Marsh
MVP [MS Access]

I would like one the comb box item be selected when the form is open, the
selected item could be anywhere within the potential items. I tried to use
the defaultvalue property, but the #name? appeared. In my form, there are
five comboxes and each one match to a different data sources( table or query)
 
M

Marshall Barton

clara said:
It works and it is what I need, but I am still confused about control source
and bound column. Could you give me a brief introduction plus an example


The Control Source of any bound **control** (including combo
boxes) contains the name of the **field** in the form's
Record Source table/query that stores the value of the combo
box.

A combo box's Bound Column specifies which field in the
combo box's Row Source table/query is used to set combo
box's value, regardless of whether the combo box is bound or
unbound.

An trivial example might be where you have a form with
Record Source
SELECT CustomerName, Phone, CountryID
FROM Customers
The form would have one text box for the name and another
for the phone number. Since you do not want to give users
an opportunity to exercise their innovative spelling skills
on country names, you have a separate Countries table with a
country ID number in column one and the country name in
column two. The form would then use a combo box with:
ControlSource CountryID
RowSource Countries
BoundColumn 1
ColumnCount 2
ColumnWidths 0;1.6

The ColumnWidths property indicates that the ID field will
not be displayed to users so they only see the country name.
However, the BoundColumn indicates that the ID field will
used to set the combo box's Value.

The combo box's ControlSource indicates that the ID value
will be saved in the CountryID field.

Side Note: A reason for saving the ID value in the
customers table instead of the country name is just in case
you want to change the country name (e.g. you decide to use
GB instead of UK), you can change it without having to go
back and modify all the customer records for that country.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top