Hi;
This is what is used in my database. Not sure if this is the best answer
but it is an answer that works.
Be sure You change the Table/Forms/Controls Names in the following code to
match the Names of Your Table/Forms/Controls.
Andy
Below is the entire answer. Read it carefully and modify it as needed. It
works.
First created "tblEmployees" with a field named EmployeeID as the primary
key and set it's "Data Type" to text.
Then created "frmEmployees" with it's Record Source as "tblEmployees"
In the "tblThatStoresMainInformation" added a field for Employees.
On the Form where the user enters the data,
("tblThatStoresMainInformation"), set the Combo box's control source to the
Employees field.
Set the Combo Box's "Row Source Type" to Table/Query
Set the Combo Box's "Row Source" to:
SELECT [tblEmployee].[EmployeeID] FROM tblEmployee;
Set "Limit to List" to Yes
In the "On Not in List" event add this code:
On Error GoTo msgbxNotInList_Err
Dim Response As Integer
Beep
MsgBox "That name is not in the list." & vbCrLf & "Please select from
the list." & vbCrLf & "To add a name to the list, Double-Click the Combo box
to open the Employees Form.", vbExclamation, ""
Response = acDataErrContinue
msgbxNotInList_Exit:
Exit Function
msgbxNotInList_Err:
MsgBox Error$
Resume msgbxNotInList_Exit
Modify and place the following code in the "On Dbl Click" event.
Private Sub cbxEmployeeID_DblClick(Cancel As Integer)
' NOTE: cbxEmployeeID is the name of my Combo box.
On Error GoTo Err_cbxEmployeeID_DblClick
Dim cbxEmployeeID As Long
If IsNull(Me![cbxEmployeeID]) Then
Me![cbxEmployeeID].text = ""
Else
lngcbxEmployeeID = Me![cbxEmployeeID]
Me![cbxEmployeeID] = Null
End If
DoCmd.OpenForm "frmEmployees", , , , , acDialog, "GotoNew"
Me![cbxEmployeeID].requery
If lngcbxEmployeeID <> 0 Then Me![cbxEmployeeID] = lngcbxEmployeeID
Exit_cbxEmployeeID_DblClick:
Exit Sub
Err_cbxEmployeeID_DblClick:
MsgBox "This Control is not working correctly."
Resume Exit_cbxEmployeeID_DblClick
End Sub