在ListBox中搜索记录 [英] Search Record Within a ListBox
问题描述
您好我是MS Access和VBA的新手,并且在这个问题上一直困扰着他们。我有一个包含表单中所有记录(~1000)的列表框,我希望能够输入内容并将其与列表框中的匹配记录匹配。我希望它的工作方式与查找完全相同功能在编辑中工具栏上的菜单,但是查找功能不会搜索列表框中的任何内容。
Private Sub cmdGoSearch_Click()
Dim SearchString As字符串
SearchString = Me.SearchBox.Value
ComputerList.SetFocus
DoCmd.FindRecord SearchString ,,, ,acAll,True
结束子
是否只是语法错误或我必须使用其他命令或没有办法在列表框中实现像我想要的查找功能?
我必须使用列表框,因为所需的界面外观就像查看详细信息中的文件一样。正常窗口的视图。我想过使用一个表单并很好地对齐它但它只是不会给你类似列表框的东西。也不希望在数据表视图中使用子表单。
请告诉我一些问题。非常感谢soooooooooooooo!
allansiu823
Hi I am new to MS Access and VBA and have been bothered by this problem for a looooong time. I have this listbox containing all the records (~1000) in a form and I want to be able to type something in and match it with the matching record IN the listbox. I want it to work exactly like the "Find" function in the "Edit" Menu on the Toolbar, however the Find function does not search anything within the listbox.
I tried tp create a textbox and its name is "SearchBox" with a command button called "cmdSearch". I have the following code on the clicking event of the command button but it says Error:
Private Sub cmdGoSearch_Click()
Dim SearchString As String
SearchString = Me.SearchBox.Value
ComputerList.SetFocus
DoCmd.FindRecord SearchString, , , , , acAll, True
End Sub
Is there just a syntax error or I have to use some other command or there is no way to implement a Find function like I desire in a listbox?
I have to use a listbox because the desired outlook of the interface is like viewing files in "Details" view of a normal window. I thought about using a form and aligning it nicely but it just won''t give you something like a listbox. Using a subform in datasheet view is not desired either.
Please shed me some light on that. Thank you soooooooooooooo much!
allansiu823
推荐答案
尝试这个,我是新的访问和vba太tho所以不知道它是否会起作用..
ListBox1.SelectedIndex = ListBox1.FindString(" SearchString")
Try this, im new to access and vba too tho so no idea if it will work..
ListBox1.SelectedIndex = ListBox1.FindString("SearchString")
试试这个,我是新手来访问和vba太了所以不知道它是否会起作用..
ListBox1.SelectedIndex = ListBox1.FindString(" SearchString" ;)
Try this, im new to access and vba too tho so no idea if it will work..
ListBox1.SelectedIndex = ListBox1.FindString("SearchString")
似乎还可以,但没有FindString方法.......任何类似的方法虽然?
It seems okay but there is no "FindString" method.......any similar methods though?
尝试FindByValue
try FindByValue
这篇关于在ListBox中搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!