A family of Microsoft relational database management systems designed for ease of use.
The code for the Click event of a button to add the name from the CustomerRef control would be like this:
Const NOCUSTMESSAGETEXT = "No customer ref entered."
Const CONFIRMMESSAGETEXT = "Add customer to Names table?"
Dim strSQL As String
If Not IsNull(Me.CustomerRef) Then
If MsgBox(CONFIRMMESSAGETEXT, vbYesNo + vbQuestion, "Confirm") = vbYes Then
strSQL = "INSERT INTO Names " & _
"VALUES(""" & Me.CustomerRef & """)"
CurrentDb.Execute strSQL, dbFailOnError
End If
Else
MsgBox NOCUSTMESSAGETEXT, vbExclamation, "Invalid Operation"
End If
Do the same for the Guest control. If you wish to avoid adding a button you could call the code in each control's DblClick event procedure. Or you could automate it to simulate the use of the NotInlist event procedure by calling the following amended code in the combo box's AfterUpdate event procedure:
Const NOCUSTMESSAGETEXT = "No customer ref entered."
Const CONFIRMMESSAGETEXT = "Add customer to Names table?"
Dim strSQL As String
Dim strCriteria As String
If Not IsNull(Me.CustomerRef) Then
strCriteria = "[YourNameField] = """ & Me.CustomerRef & """"
If IsNull(DLookup("[YourNameField]", "Names", strCriteria)) Then
If MsgBox(CONFIRMMESSAGETEXT, vbYesNo + vbQuestion, "Confirm") = vbYes Then
strSQL = "INSERT INTO Names " & _
"VALUES(""" & Me.CustomerRef & """)"
CurrentDb.Execute strSQL, dbFailOnError
End If
End If
Else
MsgBox NOCUSTMESSAGETEXT, vbExclamation, "Invalid Operation"
End If
You should then be prompted to confirm immediately upon updating the combo box by entering a name not currently represented in the Names table.
BTW I hope you have not used Name as a column name in the Names table? As the name of a built in property it is a 'reserved' word, so should be avoided as an object name. Always use more specifically descriptive names like CustomerName or, more generically, ContactName for instance.