Matt Greatorex
Registered User.
- Local time
- Today, 00:38
- Joined
- Jun 22, 2005
- Messages
- 1,019
I have a form that gets populated after the user selects a value (a person's surname) from a combo box. This works fine if the name is present or if the name is missing entirely. Where I'm having problems is if there are two people in a team e.g. the last name could be 'Davies/Smith'. I want the user to be able to search for 'Smith'.
What I would like to do is add code such that, if the entered name isn't in the list, a second combo box gets enabled and has it's source set to just those people who could possibly be the one that the user is searching for e.g. 'Davies/Smith', 'Philips/Smith', etc.
The source for this second combo box is being set correctly. However, the focus keeps returning to the first as the code loops. Consequently, the second never appears to be enabled (I'm unsure if it gets enabled, then disabled, or if it never gets enabled in the first place).
Does anyone know:
1) How I can ensure the second box gets enabled and stays that way?
2) Where I should put a SetFocus command so that, if the second combo box is enabled, focus moves to it?
The code for OnNotInList event of the first combo box is as follows:
The code for the AfterUpdate event of the first combo box is as follows:
As always, any help is gratefully appreciated.
What I would like to do is add code such that, if the entered name isn't in the list, a second combo box gets enabled and has it's source set to just those people who could possibly be the one that the user is searching for e.g. 'Davies/Smith', 'Philips/Smith', etc.
The source for this second combo box is being set correctly. However, the focus keeps returning to the first as the code loops. Consequently, the second never appears to be enabled (I'm unsure if it gets enabled, then disabled, or if it never gets enabled in the first place).
Does anyone know:
1) How I can ensure the second box gets enabled and stays that way?
2) Where I should put a SetFocus command so that, if the second combo box is enabled, focus moves to it?
The code for OnNotInList event of the first combo box is as follows:
Code:
Dim li_Count As Integer
Dim str_Source As String
Dim str_Criteria As String
On Error GoTo End_Sub
str_Criteria = "Instr(IALastname,'" & NewData & "') <> 0"
Response = acDataErrContinue
li_Count = DCount("IACode", "tbl_iainfo", str_Criteria)
If li_Count > 0 Then
str_Source = "SELECT DISTINCT tbl_iainfo.IACode, " & _
"[IALastName] & ', ' & [IAfirstname] AS Fullname, " & _
"tbl_iainfo.IALastname, " & _
"tbl_iainfo.IAFirstName " & _
"FROM tbl_iainfo " & _
"WHERE " & str_Criteria & " " & _
"ORDER BY tbl_iainfo.IALastname, tbl_iainfo.IAFirstName;"
[Forms]![frm_NBDash - IA]![cbo_Possibilities].RowSource = str_Source
[Forms]![frm_NBDash - IA]![cbo_Possibilities].Requery
[Forms]![frm_NBDash - IA]![cbo_Possibilities].Enabled = True
Else
[Forms]![frm_NBDash - IA]![cbo_Possibilities].Enabled = False
End If
Exit Sub
End_Sub:
MsgBox Err.Description
The code for the AfterUpdate event of the first combo box is as follows:
Code:
Dim str_IAcode As String
str_IAcode = [Forms]![frm_NBDash - IA]![ianame]
Call IA_Name_Change(str_IAcode) ' -- THIS FUNCTION WORKS CORRECTLY
DoCmd.Maximize
As always, any help is gratefully appreciated.