I'll try again with what I said in my last post, not last week, not some other part of a posting, but the very last post:
So.. if you highlight your locations combo on the Asset detail form, open the property form and click on the ellipses next to notinlist. Then past this exactly between the autogenerated code which will be:
Private Sub Location_NotInList(NewData As String, Response As Integer) 'Auto generated
Dim strTable As String
Dim strField As String
Dim strtitle As String
strTable = "locations"
strField = "location"
strtitle = "This Location was not found"
Response = comboboxAdd(NewData, strTable, strField, strtitle)
End sub 'Auto generated
Then, in your 'ModMapping'module paste the following exactly as it is.
'Add new to combo list
Public Function comboboxAdd(NewData As String, _
strTable As String, strField As String, strtitle As String) _
As Integer
Dim rs As DAO.Recordset
Dim StrSql As String
Dim StrMessage As String
Dim intResponse As Integer
'Set up message box to confirm
StrMessage = "'" & NewData & "' was not found " & _
Chr(10) & "Do you want to add this to the list?"
' strtitle = "Surname not Found"
If MsgBox(StrMessage, vbYesNo + vbInformation, strtitle) = vbYes Then
Set rs = CurrentDb.OpenRecordset(strTable, dbOpenDynaset)
rs.AddNew
rs.Fields(strField) = NewData
rs.Update
intResponse = acDataErrAdded
' Clean up
rs.Close
Set rs = Nothing
Else
' response is no, so show list for another selection
intResponse = acDataErrContinue
End If
comboboxAdd = intResponse
End Function
I know this works perfectly in your database if you follow the instructions. So, if you add it exactly as I have instructed with the function in the 'ModMapping' module module and the other part behind the locations combo
not in list, on the 'Asset Details' form it will work.
When you have pasted the code, save it and test it:
Open the form 'Asset details'
click on the locations combo and type in the name of a location you don't already have. when you lose focus (click somewhere else on the form) you will get a popup to say that location is not in the list, do you want to
add it. Click yes and it will add the new location to the list. DONE.
The only compile error comes from the code you added previously behind cboMainCategory_NotInList which needs to be deleted:
Private Sub cboMainCategory_NotInList(NewData As String, Response As Integer)
On Error GoTo Error_Handler
Dim intAnswer As Integer
intAnswer = MsgBox("""" & NewData & """ is not an approved category. " & vbcrlf _
& "Do you want to add it now?" _ vbYesNo + vbQuestion, "Invalid Category")
Select Case intAnswer
Case vbYes
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tlkpCategoryNotInList (Category) "
& _ "Select """ & NewData & """;"
DoCmd.SetWarnings True
Response = acDataErrAdded
Case vbNo
MsgBox "Please select an item from the list.", _
vbExclamation + vbOKOnly, "Invalid Entry"
Response = acDataErrContinue
End Select
Exit_Procedure:
DoCmd.SetWarnings True
Exit Sub
Error_Handler:
MsgBox Err.Number & ", " & Error Description
Resume Exit_Procedure
Resume
End Sub