Late to this thread and only having read the titlePerhaps this sample is doing the sort of thing you are after.
can you post the SQL/RowSource for the combobox please?
SELECT [Poems].[ID], [Poems].[Title], [Poems].[Year Completed], [Poems].[Blog Location] FROM Poems ORDER BY [Title];
OK, thank you for that.
I think you will find the problem is related to which column you are looking at. In your code you have this line Left(Me.Submission.Column(2), iLength) = Me.TxtFind Then
This is looking at [Poems].[Year Completed] but i suspect it is supposed to be looking at [Poems].[Title] which is column(1). The reason? Columns start at 0. Columns.Count = 1 column less than number of fields in the list/combo box.
If you are using a multi-select list box (list box's Multi-Select property is set to either Simple or Extended) then you can't refer to it for the value. You have to iterate through the ItemsSelected collection.They all return Null. 0, 1, 2, 3, 4, 5, 6, 7, 10, 1000. Always Null. I think "2" was just the last one I tried. I stepped through the For loop about 30 cycles, too, changing the column index to see if I could find the one that wouldn't return Null. :-/ No luck. :banghead:
If you are using a multi-select list box (list box's Multi-Select property is set to either Simple or Extended) then you can't refer to it for the value. You have to iterate through the ItemsSelected collection.
Maybe I can create a non-multi-select field that's invisible and use it in a way similar to the way the invisible text box is used. I'll explore this idea later, actually. Somehow I think this idea has merit. Yeah iterate through the non-multi-select ListBox while setting the index for the visible multi-select listbox. Might work.
Public Function MoveTo()
Dim TitleData As ADODB.Recordset
Dim SubLookup As Variant
Set TitleData = CurrentProject.Connection.Execute("SELECT [Poems].[ID], [Poems].[Title] FROM Poems ORDER BY [Title];")
SubLookup = TitleData.GetRows
Dim iLength As Integer
Dim irow As Integer
iLength = Len(Me.TxtFind)
For irow = 0 To Me.Submissions.ListCount - 1
Me.Submissions.ListIndex = irow
If Left(SubLookup(1, irow), iLength) = Me.TxtFind Then
Exit For
End If
Next
End Function
Option Compare Database
Public Function GetLetter(KeyCode As Integer, ByRef Shift As Integer) As String
Dim isLetter As String
Select Case KeyCode
Case 32
isLetter = " "
KeyCode = 0
Case 48: isLetter = "0"
Case 49: isLetter = "1"
Case 47: isLetter = "2"
Case 48: isLetter = "3"
Case 49: isLetter = "4"
Case 50: isLetter = "5"
Case 51: isLetter = "6"
Case 52: isLetter = "7"
Case 53: isLetter = "8"
Case 54: isLetter = "9"
Case 65: isLetter = "a"
Case 66: isLetter = "b"
Case 67: isLetter = "c"
Case 68: isLetter = "d"
Case 69: isLetter = "e"
Case 70: isLetter = "f"
Case 71: isLetter = "g"
Case 72: isLetter = "h"
Case 73: isLetter = "i"
Case 74: isLetter = "j"
Case 75: isLetter = "k"
Case 76: isLetter = "l"
Case 77: isLetter = "m"
Case 78: isLetter = "n"
Case 79: isLetter = "o"
Case 80: isLetter = "p"
Case 81: isLetter = "q"
Case 82: isLetter = "r"
Case 83: isLetter = "s"
Case 84: isLetter = "t"
Case 85: isLetter = "u"
Case 86: isLetter = "v"
Case 87: isLetter = "w"
Case 88: isLetter = "x"
Case 89: isLetter = "y"
Case 90: isLetter = "z"
Case 189: isLetter = "-"
End Select
GetLetter = isLetter
End Function
Public Function MoveTo()
Dim TitleData As ADODB.Recordset
Dim SubLookup As Variant
Set TitleData = CurrentProject.Connection.Execute("SELECT [Poems].[ID], [Poems].[Title] FROM Poems ORDER BY [Title];")
SubLookup = TitleData.GetRows
Dim iLength As Integer
Dim irow As Integer
iLength = Len(Me.TxtFind)
For irow = 0 To Me.Submissions.ListCount - 1
Me.Submissions.ListIndex = irow
If Left(SubLookup(1, irow), iLength) = Me.TxtFind Then
Exit For
End If
Next
End Function
Private Sub Submissions_Enter()
'Need this here to override default behavior for Enter key
End Sub
Private Sub Submissions_KeyDown(KeyCode As Integer, Shift As Integer)
Me.TxtFind.BorderStyle = 1
Me.TxtFind.BorderWidth = 0
Select Case KeyCode
Case vbKeyUp, vbKeyDown, vbKeyRight, vbKeyLeft, vbKeyShift, _
vbKeyTab, vbKeyControl, 18: Exit Sub
Case vbKeyEscape, vbKeyTab
If KeyCode = vbKeyEscape Then KeyCode = 0
Me.TxtFind = ""
Me.TxtFind.BorderStyle = 0
Case vbKeyBack
If Me.TxtFind = "" Then Exit Sub
Me.TxtFind = Left(Me.TxtFind, Len(Me.TxtFind) - 1)
MoveTo
Case vbKeyReturn
If Me.Submissions.Selected(Me.Submissions.ListIndex) = True Then
Me.Submissions.Selected(Me.Submissions.ListIndex) = False
Else
Me.Submissions.Selected(Me.Submissions.ListIndex) = True
End If
KeyCode = 0
Case Else
If Me.TxtFind = "" Then
Me.TxtFind = GetLetter(KeyCode, Shift)
Else
Me.TxtFind = Me.TxtFind & GetLetter(KeyCode, Shift)
End If
MoveTo
End Select
Me.TxtFind.SetFocus
Me.Submissions.SetFocus
End Sub