combo box default selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a combo box on it that is populated with items from
another table. I have it so that it is sorted alphabetically but rather than
the first item in the list being selected as the default choice, it select
the first item I entered into the table as the default selection. How do I
make it always default to the first item in the combo list?

thanks.
 
Sorry I'm new to Access so I may need a little more help. For my RowSource
this is what I have now:

SELECT tblOfficeInfo.OfficeName FROM tblOfficeInfo ORDER BY
tblOfficeInfo.OfficeName;

If I look at the SQL View it shows:

SELECT tblOfficeInfo.OfficeName
FROM tblOfficeInfo
ORDER BY tblOfficeInfo.OfficeName;

So where do I fit your line in at?? Thanks.
 
I've done that but it is still select the first value in the first row of the
table rather than the first value in the list which has been sorted
alphabetically.
 
Now I'm confused. It the rowsource has been sorted alphabetically, why is
the first row not the first entry in the table in the sort order?
 
Not as confused as me. You saw my code earlier, I have the rowsource set to
order by OfficeName and the list is in order by OfficeName but for some
reason the combo box is not defaulting to the first item in the list but
rather the first item I entered into the table that the list is being created
from.
 
When you say "defaulting to", do you mean it is at the top of the list? or
the item is further down in the list, and it is the one highlighted?
 
That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.
 
Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les
 
works fine for me, but it would be worth trying your method.

lwells said:
Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les

Klatuu said:
That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.
 
Hi Klatuu,

Actually what I was wanting was how you entered the syntax into the default
value of the combobox to make your method work. I tried playing around with
different variations and came up with nothing. I am always wanting to see
what others use for various methods and then try to understand the logic
behind it.

Just curious,
Les

Klatuu said:
works fine for me, but it would be worth trying your method.

lwells said:
Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les

Klatuu said:
That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.

:

Its further down the list but is the one highlighted.

:

When you say "defaulting to", do you mean it is at the top of the list? or
the item is further down in the list, and it is the one highlighted?

:

Not as confused as me. You saw my code earlier, I have the rowsource set to
order by OfficeName and the list is in order by OfficeName but for some
reason the combo box is not defaulting to the first item in the list but
rather the first item I entered into the table that the list is being created
from.

:

Now I'm confused. It the rowsource has been sorted alphabetically, why is
the first row not the first entry in the table in the sort order?

:

I've done that but it is still select the first value in the first row of the
table rather than the first value in the list which has been sorted
alphabetically.

:

Put it in the default value property of the combo box.

:

Sorry I'm new to Access so I may need a little more help. For my RowSource
this is what I have now:

SELECT tblOfficeInfo.OfficeName FROM tblOfficeInfo ORDER BY
tblOfficeInfo.OfficeName;

If I look at the SQL View it shows:

SELECT tblOfficeInfo.OfficeName
FROM tblOfficeInfo
ORDER BY tblOfficeInfo.OfficeName;

So where do I fit your line in at?? Thanks.

:

Me.cboMyCombo.ListIndex = 0

:

I have a form with a combo box on it that is populated with items from
another table. I have it so that it is sorted alphabetically but rather than
the first item in the list being selected as the default choice, it select
the first item I entered into the table as the default selection. How do I
make it always default to the first item in the combo list?

thanks.
 
I'm lost with this flipping back and forth. Are you saying to type
?forms!FormName!ComboboxName.ListIndex someplace? If so, where? Thanks.
 
The ItemData property returns the value for the bound column of the currently
selected row.
The ListIndex either returns or sets the selected row.
That is the difference.
Just for fun, open a form that has a combo box. Select the 3rd row in the
list. Then go to your VBA editor and type in ?Me.MyComboBox.ListIndex. It
should return 2
Then type in Me.MyComboBox.ListIndex = 0. The look at the combo and see
what is highlighted. It should be the first row in the list. So, if you
entered:
?Me.MyComboBox.ItemData(Me.MyComboBox.ListIndex) should return the value of
the bound column in the selected row.
OOPS!, can't use Me in immediate, where I wrote Me. change it to:
forms!MyFormName!

lwells said:
Hi Klatuu,

Actually what I was wanting was how you entered the syntax into the default
value of the combobox to make your method work. I tried playing around with
different variations and came up with nothing. I am always wanting to see
what others use for various methods and then try to understand the logic
behind it.

Just curious,
Les

Klatuu said:
works fine for me, but it would be worth trying your method.

lwells said:
Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les

:

That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.

:

Its further down the list but is the one highlighted.

:

When you say "defaulting to", do you mean it is at the top of the list? or
the item is further down in the list, and it is the one highlighted?

:

Not as confused as me. You saw my code earlier, I have the rowsource set to
order by OfficeName and the list is in order by OfficeName but for some
reason the combo box is not defaulting to the first item in the list but
rather the first item I entered into the table that the list is being created
from.

:

Now I'm confused. It the rowsource has been sorted alphabetically, why is
the first row not the first entry in the table in the sort order?

:

I've done that but it is still select the first value in the first row of the
table rather than the first value in the list which has been sorted
alphabetically.

:

Put it in the default value property of the combo box.

:

Sorry I'm new to Access so I may need a little more help. For my RowSource
this is what I have now:

SELECT tblOfficeInfo.OfficeName FROM tblOfficeInfo ORDER BY
tblOfficeInfo.OfficeName;

If I look at the SQL View it shows:

SELECT tblOfficeInfo.OfficeName
FROM tblOfficeInfo
ORDER BY tblOfficeInfo.OfficeName;

So where do I fit your line in at?? Thanks.

:

Me.cboMyCombo.ListIndex = 0

:

I have a form with a combo box on it that is populated with items from
another table. I have it so that it is sorted alphabetically but rather than
the first item in the list being selected as the default choice, it select
the first item I entered into the table as the default selection. How do I
make it always default to the first item in the combo list?

thanks.
 
It's almost like its doing the row select BEFORE the alpha sort.

Klatuu said:
The ItemData property returns the value for the bound column of the currently
selected row.
The ListIndex either returns or sets the selected row.
That is the difference.
Just for fun, open a form that has a combo box. Select the 3rd row in the
list. Then go to your VBA editor and type in ?Me.MyComboBox.ListIndex. It
should return 2
Then type in Me.MyComboBox.ListIndex = 0. The look at the combo and see
what is highlighted. It should be the first row in the list. So, if you
entered:
?Me.MyComboBox.ItemData(Me.MyComboBox.ListIndex) should return the value of
the bound column in the selected row.
OOPS!, can't use Me in immediate, where I wrote Me. change it to:
forms!MyFormName!

lwells said:
Hi Klatuu,

Actually what I was wanting was how you entered the syntax into the default
value of the combobox to make your method work. I tried playing around with
different variations and came up with nothing. I am always wanting to see
what others use for various methods and then try to understand the logic
behind it.

Just curious,
Les

Klatuu said:
works fine for me, but it would be worth trying your method.

:

Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les

:

That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.

:

Its further down the list but is the one highlighted.

:

When you say "defaulting to", do you mean it is at the top of the list? or
the item is further down in the list, and it is the one highlighted?

:

Not as confused as me. You saw my code earlier, I have the rowsource set to
order by OfficeName and the list is in order by OfficeName but for some
reason the combo box is not defaulting to the first item in the list but
rather the first item I entered into the table that the list is being created
from.

:

Now I'm confused. It the rowsource has been sorted alphabetically, why is
the first row not the first entry in the table in the sort order?

:

I've done that but it is still select the first value in the first row of the
table rather than the first value in the list which has been sorted
alphabetically.

:

Put it in the default value property of the combo box.

:

Sorry I'm new to Access so I may need a little more help. For my RowSource
this is what I have now:

SELECT tblOfficeInfo.OfficeName FROM tblOfficeInfo ORDER BY
tblOfficeInfo.OfficeName;

If I look at the SQL View it shows:

SELECT tblOfficeInfo.OfficeName
FROM tblOfficeInfo
ORDER BY tblOfficeInfo.OfficeName;

So where do I fit your line in at?? Thanks.

:

Me.cboMyCombo.ListIndex = 0

:

I have a form with a combo box on it that is populated with items from
another table. I have it so that it is sorted alphabetically but rather than
the first item in the list being selected as the default choice, it select
the first item I entered into the table as the default selection. How do I
make it always default to the first item in the combo list?

thanks.
 
I think you got confused with my answer to lwells question.
In your case, I think the code I originally sent should go in the Open event
of the form. If that doesn't work, try the Activate event.
 
I finally got this suggestion to work for me as well. Glad to be done with it.

lwells said:
Klatuu,

Pardon me for jumping in here...but I am curious with the listindex = 0 I
wasn't able to make it work either...however when I use the default like this:
=[ComboBoxName].[ItemData](0)

It will work...
How do you get your method to work?

Thanks,
Les

Klatuu said:
That makes no sense. I have never seen this happen.
Try opening your VBA editor, then going back to the database, open the form
with the combo box on it. Then go back to VBA and in the immediate window:
?forms!FormName!ComboboxName.ListIndex
It will return the current index number. If it comes back as 0 then I think
I will go play in the traffic. If not, then try
forms!FormName!ComboboxName.ListIndex = 0
and go back to the database and see which row is highlighted.
 
Back
Top