Yes, agree with nico.
Main Topics
Browse All TopicsWhat is the correct code for doing combo box smart searches in Access?
I have written VB 6.0 applications that use smart search logic for combo boxes. I have the need to use this type of logic on a form in an Access 97 database application, but the logic isn't the same. One issue is that the SendMessage call in the VB code requires the handle of the combo box, while access only has a property (hWnd) for at the form/report level, not the control level. Another issue is the difference in the way the combo list items are referenced.
Below are some pieces of my modified VB code for Access that doesn't work. It always goes to the first item in the list, based on the using the form's window handle? Any ideas on how to fix this?
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Global Const CB_FINDSTRING = &H14C
Private Sub cboRepNum_KeyPress(KeyAsci
Dim intIndex As Long
Dim strTemp As String
'Figure out the string prefix to search for
If cboRepNum.SelStart = 0 Then
strTemp = cboRepNum.Text & Chr(KeyAscii)
Else
strTemp = Left(cboRepNum.Text, cboRepNum.SelStart) & Chr(KeyAscii)
End If
Dim intWindowHandle As Long
intWindowHandle = Screen.ActiveForm.hwnd
intIndex = SendMessage(intWindowHandl
'-1 return code indicates failure to find the string
If intIndex <> -1 Then
'SendMessage returns the index of the first occurrence
cboRepNum.ListIndex = intIndex
'Set the text selection appropriately for the suggested match
cboRepNum.SelStart = Len(strTemp)
cboRepNum.SelLength = Len(cboRepNum.Text) - Len(strTemp)
KeyAscii = 0
End If
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is how you get the hWnd of a control in Access. I also agree with Nico though that Access automatically will find an item in a combobox based on what you type in in the edit control of the combobox.
'-------------------------
'Taken from Dev Ashish web site www.mvps.org/access
'
'When an Access control on a form receives the focus,
'it becomes a true window and it's possible to retrieve
'it's handle by using the GetFocus API. Note that
'because Access controls do not behave like VB controls,
'there's not a whole lot that we can do with the hWnd.
'
'Joe Kendall 8/13/2001
'-------------------------
Private Declare Function GetFocus Lib "user32" () As Long
Public Function fhWnd(ctl As Control) As Long
On Error Resume Next
ctl.SetFocus
If err Then
fhWnd = 0
Else
fhWnd = GetFocus
End If
On Error GoTo 0
End Function
Thanks!
Joe
Business Accounts
Answer for Membership
by: nico5038Posted on 2002-06-26 at 17:24:52ID: 7112411
Hi,
I'm not sure what you mean with the "combo box smart searche".
Normally in access the combobox already has a feature called "autoappend". This will show matches as long as they are present in the underlaying table/query.
Can you explain what you want to do "functionally" ?
Nic;o)