Not in List

Giganews Newsgroups
Subject: Not in List
Posted by:  rwpearson1…
Date: Wed, 21 Mar 2018

Hi there

Below is the code which I am using to add data to a combo box. I have three combo boxes but only one of them will work. I have studied all the settings etc but it seems that I can only operate one box on this form....the other two throw up an error.

Does anyone have any ideas Please?


Private Sub cboTopic_NotInList(strNewData As String, intResponse As Integer)

'Set Limit to List property to Yes

  Dim strTitle As String
  Dim intMsgDialog As Integer
  Dim strMsg1 As String
  Dim strMsg2 As String
  Dim strMsg As String
  Dim cbo As Access.ComboBox
  Dim strTable As String
  Dim strEntry As String
  Dim strFieldName As String

  strTable = "tblTopics"    '  or  tblCategory    or  tblVenue
  strEntry = "Entry"
  strFieldName = "Topic"    '  or  Category        or  Venue
  Set cbo = Me![cboTopic]    '  or  cboCategory    or  cboVenue

  'Display a message box asking if the user wants to add a new entry
  strTitle = strEntry & " Not in List"
  intMsgDialog = vbYesNo + vbExclamation + vbDefaultButton1
  strMsg1 = "Do you want to add "
  strMsg2 = " as a new " & strEntry & " entry?"
  strMsg = strMsg1 + strNewData + strMsg2
  intResponse = Msgbox(strMsg, intMsgDialog, strTitle)

  If intResponse = vbNo Then
      intResponse = acDataErrContinue
      'GoTo ErrorHandlerExit

  ElseIf intResponse = vbYes Then
      'Add new record to lookup table
      Set dbs = CurrentDb
      Set rst = dbs.OpenRecordset(strTable)
      rst(strFieldName) = strNewData

      'Continue without displaying default error message
      intResponse = acDataErrAdded

  End If