【发布时间】:2016-04-21 10:57:34
【问题描述】:
我有一个由记录集填充的列表框。然后我试图根据另一个记录集中的值选择该列表框中的项目。我能够填充列表框,但是当我尝试基于另一个记录集选择值时,列表框 Me.ToolUsed1 为 Null。我调用另一个函数来选择值,因为我计划对其他列表框使用相同的过程。非常感谢您提供的任何帮助。
'Populate the tool list box
While Not rsToolList.EOF
Me.ToolUsed1.AddItem Item:=rsToolList.Fields(0)
rsToolList.MoveNext
Wend
matchKey = "MatchKey = """ & rsActivities.Fields(0) & """"
If rsTools.RecordCount > 0 Then
rsTools.MoveFirst
rsTools.FindFirst (matchKey)
toolIndex = rsTools.Fields(2)
While Not rsTools.EOF
If (rsTools.Fields(2) = toolIndex) Then
SelectListValues Me.ToolUsed1, rsTools.Fields(1)
End If
rsTools.MoveNext
Wend
End If
Private Sub SelectListValues(tempListBox As Object, selectString As String)
Dim i As Integer
Dim found As Boolean
i = 0
found = False
'select the value in the listbox
While i < tempListBox.ListCount And Not found
If tempListBox.Value(i) = selectString Then
tempListBox.Selected(i) = True
found = True
End If
i = i + 1
Wend
'if the string wasn't found, add it
If Not found Then
tempListBox.AddItem (selectString)
End If
End Sub
【问题讨论】:
标签: ms-access select listbox vba ms-access-2010