I have combo box based on field from table. I want to add new item that is not In my combo box. In combo box cboProductType on Not in List event I have this code:
On Error GoTo ErrorH
Dim strTmp As String
Dim dbs As DAO.Database
'Get confirmation that this is not just a spelling error.
strTmp = "Add '" & NewData & "' as a new Expense Type?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
'Append the NewData as a record in the tblProduct table.
strTmp = "INSERT INTO tblProduct ( ProductTypeDescription ) " & _
"SELECT """ & NewData & """ AS ProductTypeDesription;"
dbs.Execute strTmp, dbFailOnError
'Notify Access about the new record, so it requeries the combo.
Response = acDataErrAdded
Response = acDataErrDisplay
MsgBox "When trying to process this new record add, error happened" & _
vbCrLf & "Please contact the program designer and " & _
"report the error as follows" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Description: " & Err.Description
When I enter new item I got message from error handler Error#91
Description: Object variable or With block variable not set