Okay, there are only two things you need to do. First, to get the value to
be selectable in the combo box, you need to requery it. Then you need to
position the form on the new record. See code added below
--
Dave Hargis, Microsoft Access MVP
redFred said:
I found this at Microsoft and modified a little.
The following code adds the record fine. But I want the user to view that
record, to complete the entry process, immediately after the record is added.
How do code it to return to the new record?
Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Dim NewID As String
On Error GoTo Err_ClientID_NotInList
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new client.
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a client, set the
Response argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again."
Else
' If the user chose to add a new client, open a
recordset using the clients table.
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("tbl 1 Client",
dbOpenDynaset)
' Create a new record.
Rs.AddNew
' Assign the NewID to the ClientID field.
Rs![ClientID] = NewData
' Save the record.
Rs.Update
'Update the form's recordset
Me.Requery
'Update the Combo box (I am not sure this is necessary after requerying the
form, but just in case)
Me.cboClient.Requery
'Make the New Record Current:
With Me.RecordsetClone
.FindFirst "[ClientID] = " & NewData
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End If
' Set Response argument to indicate that new
data is being added.
Response = acDataErrAdded
End If
Exit_ClientID_NotInList:
Exit Sub
Err_ClientID_NotInList:
' An unexpected error occurred, display the normal error
message.
MsgBox Err.Description
' Set the Response argument to suppress an error message
and undo changes.
Response = acDataErrContinue
End Sub