Position in a combobox

  • Thread starter Thread starter John
  • Start date Start date
J

John

Access V97.
I have a 5 to 8 row combo box [cboOC1] with column heads.
I do a gotocontrol to [cboOC1] and also a dropdown.
Everything OK to this point.

This leaves the selection on the header row, so the user has
to cursor down (down arrow) one time before an actual selection
is highlited.

I would like to place the selection on the first actual selection.
Looks like the Selected property is what I need, but that's
for listboxes.

Is there a method to do this for a combo?

Thankyou
John
 
Select the combobox and go to properties. Where it says Show Column Heads,
change to No. Add a label(s) above the combobox to identify the column(s).

Steve
(e-mail address removed)
 
Steve,
Unfortunately that might work for a fixed control, like a listbox,
but a combo list can open in different positions depending on how
many records are returned. If a dropdowned list of a combo hits the
screen edge or screen bottom, it shifts itself to a new position, in an
attempt
to show the complete list.
All eight of these combos by necessity are located low on the form, and
usually deliver 3 to 8, but as many as 10 selections, so they will all
dropdown into a different position accordingly.
Thanks for your reply,
John

Steve said:
Select the combobox and go to properties. Where it says Show Column Heads,
change to No. Add a label(s) above the combobox to identify the column(s).

Steve
(e-mail address removed)



John said:
Access V97.
I have a 5 to 8 row combo box [cboOC1] with column heads.
I do a gotocontrol to [cboOC1] and also a dropdown.
Everything OK to this point.

This leaves the selection on the header row, so the user has
to cursor down (down arrow) one time before an actual selection
is highlited.

I would like to place the selection on the first actual selection.
Looks like the Selected property is what I need, but that's
for listboxes.

Is there a method to do this for a combo?

Thankyou
John
 
I forgot two critical items in my question.
1. cboOC1 is an unbound combobox
2. I don't want to select the first legitimate record, just
position the selector there.
Thanks everyone...
John
 
Linq,
Thanks for the reply, but I did experiment with that.

My fault for not including the fact that I don't want to actually
select the value in the first data row, just move the selection highlite to
it.
From there the user can cursor down to their actual selection.

When the combo .dropdown occurs, nothing is selected.
The first down arrow it reveives, places it in the first data row.
I would imagine that Access considers that to be Row(0), as
headers may not count.
I'm just trying to send that down arrow (without sendkeys) to the combo,
and was surprised that I can't seem to find anything to do that.

Believe me, I'm not going to beat this to death. If there's no obvious
solution, everything works just fine, and one keystroke isn't that serious.
More of a "why not" question

Thanks,
John
 
John said:
I forgot two critical items in my question.
1. cboOC1 is an unbound combobox
2. I don't want to select the first legitimate record, just
position the selector there.


I think the closest you're likely to come is:

With Me.cboOC1
.SetFocus
.Value = .ItemData(0)
.Dropdown
End With
 
Dirk,
Given the column heads, ItemData(0) = "OC"
which is the header for the bound column! I never realized
that the column heads were part of the dataset.

But, if you think that I'm not going to be able to easily move
the selector highlite to the first data row, then that's what I needed to
know.

It just seemed odd that there wasn't an obvious way to do that, and that's
why I asked.
I'm not going to fight Access on this one. Not for just one keystroke.
Thanks
John M
 
John said:
Dirk,
Given the column heads, ItemData(0) = "OC"
which is the header for the bound column! I never realized
that the column heads were part of the dataset.

Did you check to verify that that was the case? In my test, using a combo
box with column heads (Access 2003), .ItemData(0) was still the value of the
first data row, not the header. But if this:

.... doesn't work for you, you should be able to use the .ListIndex property:

.ListIndex = Abs(.ColumnHeads)

That should work whether the column headers are present or not.
But, if you think that I'm not going to be able to easily move
the selector highlite to the first data row, then that's what I needed to
know.

One or another of the code options I posted will work, so long as you
understand that, with a combo box, there is no built-in way to highlight a
row without effectively setting the combo box's value to that row. The best
you can do (without some really elaborate Windows API programming) is to
select the row and then do the .Dropdown.
It just seemed odd that there wasn't an obvious way to do that, and that's
why I asked.
I'm not going to fight Access on this one. Not for just one keystroke.

Depending on what you want, the above approach may be fine for you.
 
Dirk,
Yes, I did test your code (Access 97, unbound combo)
With Me.cboOC1
.SetFocus
.Value = .ItemData(0)
.Dropdown
End With
gave me "OC" (the header) for a combo value.
ItemData(1) gave me 16955, the first real value.

This code:
With Me.cboOC1
.SetFocus
.ListIndex = Abs(.ColumnHeads)
.Dropdown
End With
gave me a R/T 7777 error "You used the ListIndex property improperly."
understand that, with a combo box, there is no built-in way to highlight a
row without effectively setting the combo box's value to that row...
At this point, I would agree, and I'm grateful for your concurrence in that.

Thanks Dirk,
John M
 
John said:
Dirk,
Yes, I did test your code (Access 97, unbound combo)
With Me.cboOC1
.SetFocus
.Value = .ItemData(0)
.Dropdown
End With
gave me "OC" (the header) for a combo value.
ItemData(1) gave me 16955, the first real value.

Interesting. This appears to be different between Access 97 and Access
2003.
This code:
With Me.cboOC1
.SetFocus
.ListIndex = Abs(.ColumnHeads)
.Dropdown
End With
gave me a R/T 7777 error "You used the ListIndex property improperly."

Another difference. Given these results, I'd suggest you use the .ItemData
property, but indexed by Abs(.ColumnHeads):

With Me.cboOC1
.SetFocus
.Value = .ItemData(Abs(.ColumnHeads))
.Dropdown
End With

But I understand that you may have decided to give up on the idea
completely.
 
Dirk,
I'll try both your suggestions in 2003, and try to get back to you on
this thread. Having some work done in the office this week, and
may have to break the PC down for a few days.

I'll also try your code with a bound combo to see if that might make a
difference.

Always thought combo headers weren't part of the dataset, so I was
surprised too.

Yes, on this issue, I'm inclined to just let it go, as far as my app is
concerned.
Thanks,
John
 
Back
Top