I have some VBA code in the On NotInList event for my main form. It works fine except for one bit. If a new account manager is entered into the form's field, the frmAccount Manager is opened to enter the new name into the tblAccount Manager. The code should be checking to see if a name already exists.
My problem comes when I have just entered a new name. The pop-up message keeps telling me that the name does not exist and would I like to add it - this keeps looping even though I have just added the name. However, if I leave the record and come back to it, I will find the name in the drop-down list (i.e. it was added, but the checks did not pick it up.
Below is my code:
My problem comes when I have just entered a new name. The pop-up message keeps telling me that the name does not exist and would I like to add it - this keeps looping even though I have just added the name. However, if I leave the record and come back to it, I will find the name in the drop-down list (i.e. it was added, but the checks did not pick it up.
Below is my code:
Private Sub Account_Manager_NotInList(NewData As String, Response As Integer)
Dim strAccount_Manager As String
Dim intReturn As Integer, varName As Variant
strAccount_Manager = NewData
intReturn = MsgBox("Account Manager " & strAccount_Manager & " is not in the system." & " Do you want to add this Account Manager?", vbQuestion + vbYesNo, "Safetell Ltd.")
If intReturn = vbYes Then
DoCmd.OpenForm FormName:="frmAccount Manager", DataMode:=acAdd, WindowMode:=acDialog, OpenArgs:=strAccount_Manager
If IsNull(DLookup("ID", "tblAccount Manager", "[Account Manager] = """ & strAccount_Manager & """")) Then Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
Exit Sub
Response = acDataErrDisplay
End Sub