ComboBox, Don't want selected first matching from list (1 Viewer)

bignose2

Registered User.
Local time
Today, 06:11
Joined
May 2, 2010
Messages
219
Hi,
I have a combo box with ID (Hidden); surname/code ; firstname

Smith/A Abbie
Smith/B Bobby
Smith/B Bernie
Smith/B Biff
Smith/C Charlie

I type Smith/B, enter (without selecting with mouse or cursor down)
I would like it to NOT save the selection until I cursor down or Mouse click
but it has saved Smith/B Bobby as it matches the first in the list

Basically a form lists ALL matching Smith/B which is what I want at first.
However what I want next, is if I select (usually with cursor down) a specific name e.g. Smith/B .. Biff, then only lists in the form exact matches on the ID, which can work as I have the ID stored.

I can have one or the other but not both at the same time.

I have autoexpand Off but on entering the combobox I have code to auto dropdown

Just trying me.surname.SelectedIndex = -1 (or just surname.SelectIndex = -1) but both give compile error but not sure will help anyway (so not persisted at moment) unless I test for mouse click or cursor movement.

I want the combo to dropdown & show all loosely matching.

Had this for years in my DB but every now & then try to get a cleaner solution & give up. I currently have the show all matching but would prefer exact selection.

Thanks I/A
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:11
Joined
Feb 19, 2013
Messages
16,637
just so we have the full picture? what are your other combo settings?

columncount
columnwidth
boundcolumn
 

isladogs

MVP / VIP
Local time
Today, 06:11
Joined
Jan 14, 2017
Messages
18,247
The way I deal with this is to have the combobox selection populate a listbox of matching names.
The selection is then made using the listbox

See attached
 

Attachments

  • SelectStudent.jpg
    SelectStudent.jpg
    49.3 KB · Views: 56

bignose2

Registered User.
Local time
Today, 06:11
Joined
May 2, 2010
Messages
219
Hi,
thanks for the advise, might try the Listbox solution but on a bit of mission at moment, just trying to understand why I can't get this to work, slightly different approach from my first attempt.
but bit of a mess below but perhaps someone might be able to get the gist.

I have a combo which drops down with data below.
It is bases on be typing Jones/M
I then cursor down to MAX.
I would then like it to stay highlighted on 4469 Max
My code records & saves 4469 no problem but whatever I do to try & point it back to 4469 it ALWAYS has 4465 highlighted at top of combo.

4465 JONES/M MILLY
4466 JONES/M MUFFIN
4467 JONES/M MOLLY
4468 JONES/M MIDGE
4469 JONES/M MAX
4470 JONES/M MILO

ListIndex I think after update always goes back to 4465 but .selected does not highlight either. Tried all day, dozens & dozens of combinations, stepped through line by line. I have had it changing the source to the combo so only 4469 but I would actually like all still showing just highlighting mine.
I think failing as something to do with them being the same name although bound to a unique ID in column0 & specifying exact.
I will try to explain & clarify & perhaps should not have posted until completely ready but really exhausted & just wanted to get something out there.

Private Sub DSL1IDs_Click()

Debug.Print "Pre select " & Me!surname.Selected(4469) & "<>" & Me!surname.ListIndex

Me.surname.SetFocus

Me!surname.Selected(4469) = True

Debug.Print "post " & Me!surname.Selected(4469) & "<>" & Me!surname.ListIndex & "<>" & TempVars!SaveSurnameListIndex

Me.surname.Dropdown

Me!surname.ListIndex = 4469 ' afterupdate runs twice?? same result though
' Me!surname.value = Me!surname.ItemData(4469) ' has benefits, does not seem to run afterupdate but still no better

Debug.Print "END " & Me!surname.Selected(4469) & "<>" & Me!surname.ListIndex & "<>" & TempVars!SaveSurnameListIndex

End Sub


Private Sub Surname_AfterUpdate()

' global variables – using TempVar also now
SurnameChanged = True
SurnameName = surname.Column(2)
SurnameRegID = surname.Column(0)
TempVars.Add "SaveSurnameListIndex", Me!surname.ListIndex

Debug.Print "After update " & Me!surname.Selected(4469) & "<>" & Me!surname.ListIndex

End Sub


Immediate Window.
Pre select 0<>-1
post 0<>-1<>-1
After update 0<>4469 ' runs twice from the Me!surname.ListIndex
After update -1<>4469
END -1<>4465<>4469
 

Users who are viewing this thread

Top Bottom