Results 1 to 3 of 3

Thread: A keypress demo

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Baltimore,MD
    Posts
    536

    Talking A keypress demo

    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!
    Attached Files Attached Files
    Walter Richardson
    Striver2000 Christian Productions
    Iam seventeen but since I started VB in June of 01 GOD has been helping me excell by finding this great forum with a bunch of GREAT PEOPLE!

  2. #2
    New Member
    Join Date
    Oct 2001
    Location
    California
    Posts
    9
    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
    Jay

  3. #3
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    You should not do it that way. Instead make the item data the primary key

    VB Code:
    1. Sub PopulateList(lst as control)
    2. ' lst can be combo or listbox
    3. dim RST as recordset
    4. dim sSQL as string
    5.  
    6. ssql = "SELECT Fields FROM Tables"
    7. set RST = db.openrecordset(sSQL)
    8.  
    9. lst.clear
    10. with RST
    11.     .movefirst
    12.     Do until .EOF
    13.         .additem Field("fieldname")
    14.         .Itemdata(.NewIndex) = !PrimaryKey
    15.         .Movenext
    16.     Loop
    17. End with
    18.  
    19. rst.close
    20. set rst = nothing
    21.  
    22. End Sub
    23.  
    24. ' now you can use the change and click events of the list
    25. ' to get the data
    26.  
    27. Public Function ItemDataFromListIndex(lst As Control) As Variant
    28.  
    29. On Error GoTo errHandler
    30.  
    31. ItemDataFromListIndex = 0
    32. If Not IsList(lst) Then Exit Function
    33.  
    34. ItemDataFromListIndex = lst.ItemData(lst.ListIndex)
    35.  
    36. Exit Function
    37.  
    38. errHandler:
    39. LogError Error, Err, lst.Name, "bLists.ItemDataFromListIndex"
    40.  
    41. End Function
    42. Public Function ListIndexFromItemData(lst As Control, iItemData As Long) As Long
    43. Dim i As Long
    44.  
    45. ' Returns the Listindex
    46.  
    47. On Error GoTo errHandler
    48.  
    49. ListIndexFromItemData = -1
    50.  
    51. If Not IsList(lst) Then Exit Function
    52.  
    53. With lst
    54.   For i = 0 To .ListCount - 1
    55.     If .ItemData(i) = iItemData Then
    56.       ListIndexFromItemData = i
    57.       Exit Function
    58.     End If
    59.   Next i
    60. End With
    61.  
    62. Exit Function
    63.  
    64. errHandler:
    65. LogError Error, Err, lst.Name, "bLists.ListIndexFromItemData"
    66.  
    67. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width