I created a demo to help with keypress questions I hope someone finds it helpful email me with any questions or comments at [email protected]
GOD BLESS!
Printable View
I created a demo to help with keypress questions I hope someone finds it helpful email me with any questions or comments at [email protected]
GOD BLESS!
Hi Walter,
I was wondering if you could help me with the key_press event for listboxes? I have a listbox that's connected to a table in my DB.
When the user presses a number(s) (ie. 1 - 50) I need the listbox to move to, highlight, and check the listindex that matches the input. The listindex is actually the primary key of the table the listbox is linked to. Hope you can help me out with this one!
Thanks in advance!!!
Jay
You should not do it that way. Instead make the item data the primary key
VB Code:
Sub PopulateList(lst as control) ' lst can be combo or listbox dim RST as recordset dim sSQL as string ssql = "SELECT Fields FROM Tables" set RST = db.openrecordset(sSQL) lst.clear with RST .movefirst Do until .EOF .additem Field("fieldname") .Itemdata(.NewIndex) = !PrimaryKey .Movenext Loop End with rst.close set rst = nothing End Sub ' now you can use the change and click events of the list ' to get the data Public Function ItemDataFromListIndex(lst As Control) As Variant On Error GoTo errHandler ItemDataFromListIndex = 0 If Not IsList(lst) Then Exit Function ItemDataFromListIndex = lst.ItemData(lst.ListIndex) Exit Function errHandler: LogError Error, Err, lst.Name, "bLists.ItemDataFromListIndex" End Function Public Function ListIndexFromItemData(lst As Control, iItemData As Long) As Long Dim i As Long ' Returns the Listindex On Error GoTo errHandler ListIndexFromItemData = -1 If Not IsList(lst) Then Exit Function With lst For i = 0 To .ListCount - 1 If .ItemData(i) = iItemData Then ListIndexFromItemData = i Exit Function End If Next i End With Exit Function errHandler: LogError Error, Err, lst.Name, "bLists.ListIndexFromItemData" End Function