Results 1 to 25 of 25

Thread: SQL query question [Resolved]

Threaded View

  1. #20
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    AutoFill ComboBox Function

    This is what I use for a Combo AutoFill:

    In A Module:
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    2. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    3. lParam As Any) As Long
    4.  
    5. Public Function AUTOFIND(ByRef cboCurrent As ComboBox, _
    6.     ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
    7.    
    8.     Dim lCB As Long
    9.     Dim sFindString As String
    10.    
    11.     If KeyAscii = 8 Then
    12.         If cboCurrent.SelStart <= 1 Then
    13.             cboCurrent = ""
    14.             AUTOFIND = 0
    15.             Exit Function
    16.         End If
    17.             If cboCurrent.SelLength = 0 Then
    18.                 sFindString = UCase(Left(cboCurrent, Len(cboCurrent) - 1))
    19.             Else
    20.                 sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart - 1)
    21.             End If
    22.    
    23.     ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
    24.         Exit Function
    25.     Else
    26.         If cboCurrent.SelLength = 0 Then
    27.             sFindString = UCase(cboCurrent.Text & Chr$(KeyAscii))
    28.         Else
    29.             sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart) & Chr$(KeyAscii)
    30.         End If
    31.     End If
    32.     lCB = SendMessage(cboCurrent.hWnd, CB_FINDSTRING, -1, ByVal sFindString)
    33.     If lCB <> CB_ERR Then
    34.         cboCurrent.ListIndex = lCB
    35.         cboCurrent.SelStart = Len(sFindString)
    36.         cboCurrent.SelLength = Len(cboCurrent.Text) - cboCurrent.SelStart
    37.         AUTOFIND = 0
    38.     Else
    39.         If LimitToList = True Then
    40.             AUTOFIND = 0
    41.         Else
    42.             AUTOFIND = KeyAscii
    43.         End If
    44.     End If
    45. End Function

    On the Form:
    VB Code:
    1. Private Sub Combo1_KeyPress(KeyAscii As Integer)
    2. On Error GoTo Combo1_KeyPress_Error
    3.  
    4.      KeyAscii = AUTOFIND(Me.Combo1, KeyAscii, True)
    5.  
    6. On Error GoTo 0
    7. Exit Sub
    8.  
    9. Combo1_KeyPress_Error:
    10.  
    11. MsgBox "Error " & Err.Number & " (" & Err.Description & ") "  & _
    12. "in procedure Combo1_KeyPress of Form " & Me.Name
    13. End Sub
    Last edited by Mark Gambo; Sep 14th, 2005 at 07:19 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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