Scott:
Does the 'People' table from which the names are obtained contain other
fields such as FirstName and address data for instance? If so then to add a
new name via the combo box you'll need to use the combo box's NotInList event
procedure to open another form bound to the People table so that you can add
the other data before updating the combo box's list. Here's some code for
the NotinList event procedure of a cities combo box which does this. You
should be able to adapt it easily enough for people:
Private Sub cboCities_NotInList(NewData As String, Response As Integer)
Dim ctrl As Control
Dim strMessage As String
Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmCities", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
' ensure frmCities closed
DoCmd.Close acForm, "frmCities"
' ensure city has been added
If Not IsNull(DLookup("CityID", "Cities", "City = """ & _
NewData & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Cities table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
End Sub
In addition to the above code the following code goes into the frmCities
form's Open event procedure to set the DefaultValue property of the City
control to the new name entered in the combo box. Again you should be able
to adapt this easily enough:
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.City.DefaultValue = """" & Me.OpenArgs & """"
End If
End Sub
Ken Sheridan
Stafford, England