我正在为我的代码寻求一些建议/提示/更正,为什么它不能正常工作。
我有2个表格。
Form1 带有菜单栏(添加类型菜单栏),我想让它循环通过 form2 上的组合框列表(以检查列表中是否没有现有数据可以添加)。
我不明白为什么它不能在form1上工作?当我使用 1 种形式在其他项目上测试我的代码时,它可以工作。有人可以告诉我有什么问题吗?为什么?
使用 2 种形式。此代码只会添加新类型,但不会检查组合框上是否存在数据:(
Private Sub mnuAYT_Click()
Dim TypeYacht As String 'Type of yacht added
Dim blnItem As Boolean
Dim intItem As Integer
' - - - - - - - LOOP THROUGHT the combo box all items - - - - - - -
blnItem = False
intItem = 0
Do Until blnItem = True Or intItem = NewCharter.cmbTypeYacht.ListCount
If TypeYacht = NewCharter.cmbTypeYacht.List(intItem) Then
blnItem = True
End If
intItem = intItem + 1
Loop
If blnItem = True Then
MsgBox TypeYacht & " " & "is already exist", vbInformation, "Yacht Type Match"
NewCharter.cmbTypeYacht.ListIndex = intItem - 1
Else
NewCharter.cmbTypeYacht.AddItem NewCharter.cmbTypeYacht.Text
MsgBox "Successfully added new Yacht Type", vbInformation, "Successfully Added"
End If
End Sub
顺便说一句,这是我的代码,仅使用 1 种形式(添加并检查是否存在数据)
Dim TypeYacht As String 'Type of yacht added
Dim blnItem As Boolean
Dim intItem As Integer
' ----------------------------- LOOP THROUGHT the combo box all items -------------------------
blnItem = False
intItem = 0
TypeYacht = cmbTypeYacht.Text
Do Until blnItem = True Or intItem = cmbTypeYacht.ListCount
If TypeYacht = cmbTypeYacht.List(intItem) Then
blnItem = True
End If
intItem = intItem + 1
Loop
If blnItem = True Then
MsgBox TypeYacht & " " & "is already exist", vbInformation, "Yacht Type Match"
cmbTypeYacht.ListIndex = intItem - 1
Else
cmbTypeYacht.AddItem cmbTypeYacht.Text
MsgBox "Successfully added new Yacht Type", vbInformation, "Successfully Added"
End If