检查dynamic添加的combobox中的用户input数据

我正在使用用户窗体来显示在文档中find的首字母缩略词和首字母缩写词的定义。 因为我不会提前知道有多less我会创build所有的标签,dynamiccheckbox和comboBox使用下面的for循环。

我现在卡在我想让用户能够键入combobox一个新的定义是例如一个不存在于我的Excel数据库或他们想要使用一个不同的定义,我知道这是不好的做法,但不幸的是,人们不坚持标准清单)。 现在所有的工作正常,但它的设置,但我的问题是,我想检查用户是否input了新的东西或不。

所以我的问题是,是否有一个内置函数或variables这样做? 还是有一个简单的方法来做到这一点? (我已经试过并testing了将string添加到我的数据库的代码,所以这不是一个问题,只是检查它是否不存在,而无需再次从头开始运行整个数据库)

For i = 1 To n checkBoxi = "CheckBox" & i labeli = "Label" & i comboBoxi = "ComboBox" & i 'add checkbox, label and combobox .MultiPage1.Pages("Page1").Controls.Add "Forms.CheckBox.1", checkBoxi .MultiPage1.Pages("Page1").Controls.Add "Forms.Label.1", labeli .MultiPage1.Pages("Page1").Controls.Add "Forms.ComboBox.1", comboBoxi 'position check box .MultiPage1.Pages("Page1").Controls(checkBoxi).Left = LeftSpacing .MultiPage1.Pages("Page1").Controls(checkBoxi).Top = TopSpacing + rowHeight * i 'position labels .MultiPage1.Pages("Page1").Controls(labeli).Left = LeftSpacing + 15 .MultiPage1.Pages("Page1").Controls(labeli).Top = TopSpacing + 2 + rowHeight * i .MultiPage1.Pages("Page1").Controls(labeli).Caption = acronyms(i - 1) .MultiPage1.Pages("Page1").Controls(labeli).Width = 70 'position comboBox .MultiPage1.Pages("Page1").Controls(comboBoxi).Left = LeftSpacing + 100 .MultiPage1.Pages("Page1").Controls(comboBoxi).Top = TopSpacing + rowHeight * i .MultiPage1.Pages("Page1").Controls(comboBoxi).Width = 300 'find definitions for comboBox ' Find the definition from the Excel document With objWbk.Sheets("Sheet1") ' Find the range of the cells with data in Excel doc Set rngSearch = .Range(.Range("A1"), .Range("A" & .rows.Count).End(-4162)) ' Search in the found range for the Set rngFound = rngSearch.Find(What:=acronyms(i - 1), After:=.Range("A1"), LookAt:=1) ' if nothing is found count the number of acronyms without definitions If rngFound Is Nothing Then ' Set the cell variable in the new table as blank ReDim targetCellValue(0) As String targetCellValue(0) = "" ' If a definition is found enter it into the cell variable Else targetCellValue(0) = .Cells(rngFound.Row, 2).Value 'MsgBox (targetCellValue(0) & " " & 0) firstAddress = rngFound.Address Do Until rngFound Is Nothing Set rngFound = rngSearch.FindNext(After:=rngFound) If rngFound.Address = firstAddress Then Exit Do ElseIf rngFound.Address <> firstAddress Then j = j + 1 ReDim Preserve targetCellValue(0 To j) As String targetCellValue(j) = .Cells(rngFound.Row, 2).Value 'MsgBox (targetCellValue(j) & " " & j) End If Loop End If End With Dim k As Integer For k = 0 To j .MultiPage1.Pages("Page1").Controls(comboBoxi).AddItem targetCellValue(k) Next k j = 0 Next i 

我find了一个方法来做到这一点。 由用户input的值不会自动包含在combobox列表中,因此您可以根据列表检查它是否存在。

码:

 For intComboItem = 0 To .MultiPage1.Pages("Page1").Controls(comboBoxi).ListCount - 1 If .MultiPage1.Pages("Page1").Controls(comboBoxi).Value = .MultiPage1.Pages("Page1").Controls(comboBoxi).List(intComboItem) Then newDef = False Exit For Else newDef = True End If Next If newDef Then MsgBox ("new def: " & .MultiPage1.Pages("Page1").Controls(comboBoxi).Value) End If