Double Click ComboBox

C

Channell

Hello,

I was looking for a way to double click on the actual combo box in my form,
and have it automatically go to the next item in the combo box. This is
meant for convenience for the user. I know it sounds silly, but if you know
how to do this, I would greatly appreciate it. Thanks!

-Scott Channell
 
D

Dirk Goldgar

Channell said:
Hello,

I was looking for a way to double click on the actual combo box in my
form,
and have it automatically go to the next item in the combo box. This is
meant for convenience for the user. I know it sounds silly, but if you
know
how to do this, I would greatly appreciate it. Thanks!


If I'm understanding you correctly, code like this will do it:

'----- start of code -----
Private Sub cboYourCombo_DblClick(Cancel As Integer)

Dim lngNextRow As Long

With Me.cboYourCombo
lngNextRow = .ListIndex + 1
If lngNextRow >= .ListCount Then
lngNextRow = 0
End If
.Value = .ItemData(lngNextRow)
End With

End Sub
'----- end of code -----
 
T

Tom van Stiphout

On Thu, 2 Apr 2009 20:29:01 -0700, Channell

Bad idea to use non-standard UI behaviors, but I'm guessing I won't be
able to convice you, so here goes:
Private Sub myCombo_DblClick(Cancel As Integer)
myCombo.ListIndex = myCombo.ListIndex + 1
End Sub
(replace myObjectNames with yours)

-Tom.
Microsoft Access MVP
 
C

Channell

I like the Idea! Ken, One Question:

If I first drop the combo box in my form and click(select) an item in my
combo box, then use the arrow, it automatically goes back to the first item
in my combo box. I notice on your form it continues to the next item if you
do that.

What's wrong with mine? Here is the code to my combo box after update event:

Private Sub Combo20_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[LastNameFirstName] = '" & Me![Combo20] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Thanks Ken!
 
K

Ken Snell MVP

The code that you posted is not the code that is in the forms' modules that
are in the sample database.

Your posted code is designed to move the form's data to the record that
corresponds to the value chosen in the combo box. It has nothing to do with
the spin arrows that I have in the sample database.

I'm confused about what you are wanting to do?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Channell said:
I like the Idea! Ken, One Question:

If I first drop the combo box in my form and click(select) an item in my
combo box, then use the arrow, it automatically goes back to the first
item
in my combo box. I notice on your form it continues to the next item if
you
do that.

What's wrong with mine? Here is the code to my combo box after update
event:

Private Sub Combo20_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[LastNameFirstName] = '" & Me![Combo20] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Thanks Ken!

Ken Snell MVP said:
How about using spin arrows next to the combobox?

Spin arrows for combo box:
http://www.accessmvp.com/KDSnell/SampleDBs.htm#Cbospin

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 
C

Channell

Ken, Sorry to confuse you. I posted your code exactly in the two spin
buttons I made. (I had read a similar post you helped someone with, and you
asked them to post their code that the combo box held).

Anyway, I posted the code exactly (but I changed the object names of course)
and it all works as it should except for one thing. If I first select an
employee name from my combo box (say Bob), and then I use a spin arrow to get
to the next name, the combo box automatically reverts back to the first name
and then works from there. I guess what I am getting at, is I cannot go from
using the spin arrows to using the combo box drop down feature without having
the spin arrows start the Combo Box names over from the top.

I hope this makes sense. Thank you very much for the help Ken.

-Scott Channell
 
K

Ken Snell MVP

OK, now I understand. I think the reason is that, when you select an item in
the combo box, your posted code moves the form to the desired value, which
may be "resetting" the combo box's ListItem property back to the first item
in the list, even though the combo box is still showing the selected item.
My spin-button code reads the ListItem property and moves the combo box to
the next or previous item.

You can test my hypothesis by putting a breakpoint on the first code line
for the spin button; when you click the spin button, the code will "break",
and you can hover the cursor over the .ListItem property in the code to see
what it's value is. You also can test by reading the .ListItem value in your
AfterUpdate event prior to resetting the form's data to the Clone's
bookmark, and after resetting the data, to see if it changes.

If I'm correct, you'd need to set the combo box to the initial ListItem
value. Here is revised code that would do what I am thinking (note that I've
changed your use of Recordset.Clone to RecordsetClone; less overhead for the
database because the RecordsetClone object already exists, while the
database must create the Recordset.Clone object first):

Private Sub Combo20_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object, lngList As Long
lngList = Me![Combo20].ListIndex
Set rs = Me.RecordsetClone
rs.FindFirst "[LastNameFirstName] = '" & Me![Combo20] & "'"
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
Me![Combo20].Value = Me![Combo20].ItemData(lngList)
End If
Set rs = Nothing
End Sub


If you have trouble with this, send me a zipped copy of the database, with
instructions on how to reproduce and in which form, to the email address at
my website (see my signature).
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 

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

Similar Threads


Top