我在MS-Access-2007中设计了一个具有两个textbox SearchFor、SrchText和ListBox SearchResults的表单。此表单用于在SearchResults中从查询和结果中搜索记录。
SearchFor用于将值放入搜索
SrchText用作查询参数
SearchResults用于显示搜索值
这段代码运行得很好,但是当我在textbox SearchFor中输入任何以"i“开头的文本时,会出现一个错误提示Run-time error '2110': Microsoft Office Access can't move the focus to the control SearchResults。
Private Sub SearchFor_Change()
'Create a string (text) variable
Dim vSearchString As String
'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = SearchFor.Text
'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll
SrchText.Value = vSearchString
'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
Me.SearchResults.Requery
'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
Exit Sub
End If
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus
If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
End Sub发布于 2019-01-12 21:03:12
最后,我找到了一个解决方案,但我仍然不知道为什么这样做有效。
打开窗体,进入“设计”视图,突出显示搜索框,然后打开属性表。在“其他”选项卡下,有一个“允许自动更正”选项。将其设置为No,小写的"i“最终生效。
https://stackoverflow.com/questions/54159108
复制相似问题