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