hi!

can someone help me how to convert this code to public function... this code works but the problem is i have to copy it in every combo box command. here's the code
VB Code:
  1. Option Explicit
  2.  
  3. Dim InChangeMode As Boolean
  4. Dim BackSpacePressed As Boolean
  5.  
  6. Private Sub Combo1_Change()
  7. On Error Resume Next
  8. Dim idx As Integer
  9. Dim SelFrom As Integer
  10.  
  11. If InChangeMode Then Exit Sub
  12. If BackSpacePressed Then
  13. BackSpacePressed = False
  14. Exit Sub
  15. End If
  16.  
  17. With Combo1
  18. If Trim(.Text) = "" Then Exit Sub
  19. If .ListCount < 0 Then Exit Sub
  20. InChangeMode = True
  21. For idx = 0 To .ListCount
  22. If UCase(.Text) = UCase(Left(.list(idx), Len(.Text))) Then Exit For
  23.  
  24. '' If your data in Combox is sorted than add the next line
  25. ' If UCase(.Text) < UCase(Left(.List(idx), Len(.Text))) Then GoTo EndOfProcess
  26.  
  27. Next idx
  28. If idx < .ListCount Then
  29. SelFrom = Len(.Text)
  30. .ListIndex = idx
  31. .SelStart = SelFrom
  32. .SelLength = Len(.Text) - SelFrom
  33. End If
  34. End With
  35. EndOfProcess:
  36. InChangeMode = False
  37. End Sub
  38.  
  39. Private Sub Combo1_KeyPress(KeyAscii As Integer)
  40. Select Case KeyAscii
  41. Case vbKeyBack
  42. BackSpacePressed = True
  43. End Select
  44.  
  45. End Sub
  46.  
  47. Private Sub Form_Load()
  48. 'Dim idx
  49.  
  50. 'With Combo1
  51. '.Clear
  52. 'For idx = 65 To 88
  53. '.AddItem Chr(idx) & Chr(idx + 1) & Chr(idx + 2) & "test"
  54. 'Next idx
  55. 'End With
  56. InChangeMode = False
  57. BackSpacePressed = False
  58. End Sub


thanx for the help!