Combobox navigation buttons (1 Viewer)

stevekos07

Registered User.
Local time
Today, 02:07
Joined
Jul 26, 2015
Messages
174
I have a combobox on a form that has many items to select from. I would like to set up navigation buttons that navigate through the combobox one item at a time.

Am I right in thinking that this needs to be based on an "apply filter" command that selects the records based on the previous or next item in the combobox? I just can't think of the best way to approach this. (Besides, I am tired and it's been a long day :D).

Cheers.
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 05:07
Joined
Oct 17, 2012
Messages
3,276
Why not just use a list box instead, then?

Otherwise you would need to use Me.cboComboBoxName.Column(x,y) where x is the bound column and y is the row number (both starting with 0).
 

Mark_

Longboard on the internet
Local time
Today, 02:07
Joined
Sep 12, 2017
Messages
2,111
As a follow up, if you'd rather not go with Frothingslosh suggestion have you thought about cascading combo boxes?

And by "Many Items", what kind of number are we talking about? 20's, 100's, 1000's?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:07
Joined
Feb 19, 2002
Messages
42,981
As long as the combo box is properly sorted by the visible field, it will scroll itself as you type.

If I have a list of state names and I start typing,
C brings me to California
Co brings me to Colorado
Con brings me to Connecticut
 

MarkK

bit cruncher
Local time
Today, 02:07
Joined
Mar 17, 2004
Messages
8,178
I was curious if this could be done, and it can...
Code:
Private Sub cmdDown_Click()
    With Me.cbTestCombo
        If .ListIndex = .ListCount Then
            .Value = .ItemData(0)
        Else
            .Value = .ItemData(.ListIndex + 1)
        End If
        .SetFocus
        .Dropdown
    End With
End Sub
...but I wouldn't. I think AutoComplete, what Pat is talking about, is way more useful, or, I prefer to allow the user to type a few characters in a textbox, and search a list that way, for substrings. But it seems cumbersome to step one row at a time like this in a control.
hth
Mark
 

Mark_

Longboard on the internet
Local time
Today, 02:07
Joined
Sep 12, 2017
Messages
2,111
@Mark,
More interesting variant would be
Code:
Private Sub cmdDown_Click()
    With Me.cbTestCombo
        If (.ListIndex + .ListRows) >= .ListCount Then
            .Value = .ItemData(0)
        Else
            .Value = .ItemData(.ListIndex + .ListRows)
        End If
        .SetFocus
        .Dropdown
    End With
End Sub

That way you go down one page at a time instead of one item at a time.
 

MarkK

bit cruncher
Local time
Today, 02:07
Joined
Mar 17, 2004
Messages
8,178
Yeah, that makes is more useful, but I still wouldn't do it.
 

Mark_

Longboard on the internet
Local time
Today, 02:07
Joined
Sep 12, 2017
Messages
2,111
@Mark,

So its a better version of a bad idea? Does it hit "Optimized uselessness"?
 

MarkK

bit cruncher
Local time
Today, 02:07
Joined
Mar 17, 2004
Messages
8,178
Lol. Bad Idea 2.01 with new reduced uselessness. It's not a bug, it's a feature!
 

Users who are viewing this thread

Top Bottom