Welcome to Dream.In.Code
Getting Help is Easy!

Join 98,764 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 1,041 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!


Combo Box search problem.

 
Reply to this topicStart new topic

Combo Box search problem.

AztecUK
post 27 Apr, 2008 - 07:59 PM
Post #1


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 1


My Contributions


Hi Guys

I'm new to Access and programming, so the answer to my problem may seen obvious to seasoned users. Please be kind!

My database has a table 'tblCustomerDetails' that contains an auto number field 'CustomerID' as the PKF and two text fields 'LastName' and
'FirstName'. The other fields are not involved in my problem.
I have used a Combo Box in a form 'frmVehicleDetails' to add the Customer ID to a field on the form. The Combo Box uses the three fields from 'tblCustomerDetails' as it's Row Source.
The Combo Box lists the three fields and correctly writes the selected Customer ID to my chosen field on the form.
As there are likely to be many Customer Records, I have incorporated code as published on the web (which I do not fully understand), in order to allow the user to type the beginning of a Customer Name into the Combo Box so that only names beginning with these characters are displayed.
Unfortunately the Combo Box will only allow the search to use the 'CustomerID' field and not the 'LastName' field. I.e. typing the beginning of a Customer ID number into the Combo Box, lists the correct records.
Is the code at fault, or more likely, is my configuration of the Combo Box incorrect?

I am using Access 2007 and the code used is as follows:-

CODE
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
         (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As _
         Integer, ByVal lParam As Any) As Long

'constants for searching the ComboBox
Private Const CB_FINDSTRINGEXACT = &H158
Private Const CB_FINDSTRING = &H14C

'

'function to get find an item in the ComboBox
Public Function GetComboBoxIndex(hWnd As Long, SearchKey As String, Optional FindExactMatch As Boolean = True) As Long

    'Parameters:
    '   hWnd - the handle to the ComboBox control.  Usage:  Combo1.hWnd
    '   SearchKey - item that you would like to search for.  Can be any string - case doesn't matter when searching
    '   Optional FindExactMatch - Default is True.  Pass False to find a partial match
    'Return:
    '   Returns the index of the found match.  If the match is not found, -1 is returned
    'Usage:
    '   Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item")
    '   Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item", False)
    
    If FindExactMatch Then
        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRINGEXACT, -1, ByVal SearchKey)
    Else
        GetComboBoxIndex = SendMessage(hWnd, CB_FINDSTRING, -1, ByVal SearchKey)
    End If
    
End Function


I thank you in advance for any help or guidance you may provide.

AztecUk
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 7/20/08 02:33PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->