A family of Microsoft relational database management systems designed for ease of use.
Hi DennisWelch.
The code you are showing is for the main category combo not in list.
You need to highlight the location combo as you have done, then on the property sheet go to the not in list event, click on the ellipses to open vba editor which will add 'private sub cboLocation_notInList etc etc.
You then add the code as you have for the category not in list. You will have to make some changes to the code though to insert into the correct table i.e. location table.
I don't normally do it that way.
If you add the following function you can then use it for all combo's (on the main access menu, click create, then 'module'. copy and paste this code to the module
'Add New item to Combo
Public Function combobox(NewData As String, _
strTable As String, strField As String, StrMsgMessage As String, StrMsgTitle As String) _
As Integer
Dim rs As DAO.Recordset
Dim strSQl As String
Dim intResponse As Integer
'Set up message box to confirm
If MsgBox(StrMsgMessage, vbYesNo + vbInformation, StrMsgTitle) = 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
combobox = intResponse
End Function
then for each combo, click on the not in list event, ellipses, open vba editor (as you have previously) and add:
Private Sub cboEmpRank_NotInList(NewData As String, Response As Integer) 'this will be added automatically
Dim strTable As String
Dim strField As String
strTable = "tblRank" 'change "tblRank" to your table name for the combo
strField = "Rank" 'Change "Rank" to your field name
Response = combobox(NewData, strTable, strField)
End Sub 'also added automatically