Hi All,
I have an unbound combo box on a form called cbo_LastName. Because the row source for this combo box contains almost 100,000 distinct values, I have set it up to only load the row source after the first three characters has been entered.
So when the user starts typing, the combo box is empty. After the first three letters have been entered, say "smi" the combo box is populated and drops down. At "smi" the combo box shows "Smialy, Smikle, Smirnoff, etc" At "smit" the combo box shows "Smith, Smith Brown, Smith Hardy...Smith-Andrews, Smith-Brown, etc"
The problem comes when the user enters "smith " (smith followed by a space) or "smith-". Instead of showing all the values that begin with "smith " ie "Smith Brown" or that begin with "smith-" ie "Smith-Brown" the combo box goes blank...
The code for my combo box is below - if anyone can help, it would be much appreciated - I'm stumped!
FYI, I'm using Access as a front end to a SQL Server back end, and the row source I'm using is a pass-through query to a stored procedure. Not sure if this affects the behaviour of the combo box, but just in case.
I have an unbound combo box on a form called cbo_LastName. Because the row source for this combo box contains almost 100,000 distinct values, I have set it up to only load the row source after the first three characters has been entered.
So when the user starts typing, the combo box is empty. After the first three letters have been entered, say "smi" the combo box is populated and drops down. At "smi" the combo box shows "Smialy, Smikle, Smirnoff, etc" At "smit" the combo box shows "Smith, Smith Brown, Smith Hardy...Smith-Andrews, Smith-Brown, etc"
The problem comes when the user enters "smith " (smith followed by a space) or "smith-". Instead of showing all the values that begin with "smith " ie "Smith Brown" or that begin with "smith-" ie "Smith-Brown" the combo box goes blank...
The code for my combo box is below - if anyone can help, it would be much appreciated - I'm stumped!
FYI, I'm using Access as a front end to a SQL Server back end, and the row source I'm using is a pass-through query to a stored procedure. Not sure if this affects the behaviour of the combo box, but just in case.
Code:
Private Sub cbo_LastName_Change()
'Changes the contents of the LastName combo box after the first three letters have been entered
Dim db As DAO.Database
Set db = CurrentDb
Dim qdfLastName As DAO.QueryDef
Me.cbo_LastName.SetFocus
'Sets the Query Definition of the Last Name Lookup Query to take the value entered in the combo box
'as the input parameter
Set qdfLastName = db.QueryDefs("qry_Lkp_LastName")
qdfLastName.SQL = "usp_Lkp_LastName " & Me!cbo_LastName.Text
'When the number of letters entered in the combo box is greater than two,
'then set the rowsource of the combo box to the lookup query and drop it down
If Len(Me!cbo_LastName.Text) > 2 Then
Me!cbo_LastName.RowSource = "qry_Lkp_LastName"
Me!cbo_LastName.Dropdown
Else
Me!cbo_LastName.RowSource = ""
End If
qdfLastName.Close
End Sub