Hello,
I've cobbled together some code to do the following:
1. Look for a member in the combo box
2. If not found, go to a data entry form and add new member
3. Manually close data entry form with a button
4. Return to main form
5. The new name is now in the combo box
But when the user selects the newest addition they can't get to that record. Usually they tab to the new record, now it just goes to the first one.
If the form is closed and reopened then it works fine, so is that what I need to put in the code?
I was going to show the code for each step, but was afraid it would be too much. I've included step 1.
Thanks Susan
1. Private Sub cboFindName_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PeopleID] = " & Str(Me![CboFindName])
Me.Bookmark = rs.Bookmark
CboFindName.Value = ""
End Sub
and
Private Sub cboFindName_NotInList(NewData As String, Response As Integer)
Dim CR As String
'Where Current form is where the combo box is that this code is assigned to
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new record
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it? "
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a record, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Select another record.", vbOKOnly, "Record Not Added"
Else
' If the user chooses to add a new record, open the Add Record Form
'also set the response argument to suppress the error message
Response = acDataErrContinue
DoCmd.OpenForm "frmAddNewPerson", , , , acFormAdd, , NewData
Forms!frmAddNewPerson!LastName = NewData
Me.CboFindName.Value = 0
End If
End Sub
I've cobbled together some code to do the following:
1. Look for a member in the combo box
2. If not found, go to a data entry form and add new member
3. Manually close data entry form with a button
4. Return to main form
5. The new name is now in the combo box
But when the user selects the newest addition they can't get to that record. Usually they tab to the new record, now it just goes to the first one.
If the form is closed and reopened then it works fine, so is that what I need to put in the code?
I was going to show the code for each step, but was afraid it would be too much. I've included step 1.
Thanks Susan
1. Private Sub cboFindName_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PeopleID] = " & Str(Me![CboFindName])
Me.Bookmark = rs.Bookmark
CboFindName.Value = ""
End Sub
and
Private Sub cboFindName_NotInList(NewData As String, Response As Integer)
Dim CR As String
'Where Current form is where the combo box is that this code is assigned to
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new record
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it? "
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a record, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Select another record.", vbOKOnly, "Record Not Added"
Else
' If the user chooses to add a new record, open the Add Record Form
'also set the response argument to suppress the error message
Response = acDataErrContinue
DoCmd.OpenForm "frmAddNewPerson", , , , acFormAdd, , NewData
Forms!frmAddNewPerson!LastName = NewData
Me.CboFindName.Value = 0
End If
End Sub