ms-access - 运行时错误“2110”:`Microsoft Office Access 无法将焦点移至控件
问题描述
我在 MS-Access-2007 中设计了一个表单,它有两个 textboxSearchFor
和SrchText
一个 ListBox SearchResults
。此表单用于从查询中搜索记录,结果显示在SearchResults
.
SearchFor
用于放置要搜索的值
SrchText
用作查询参数
SearchResults
用于出现搜索值
这段代码运行完美,但是当我在文本框中输入任何以“i”开头的文本时,会SearchFor
出现错误提示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
解决方案
最后,我找到了解决方案,但我仍然不知道为什么会这样。
打开表单,进入设计视图,突出显示搜索框并打开属性表。在“其他”选项卡下,有一个“允许自动更正”选项。将其设置为“否”,小写“i”终于可以工作了。
推荐阅读
- xcode - 查看文本字段的文本后缀
- javascript - 访问 json 对象中的元素
- python - FileExistsError: [WinError 183] 即使不是 os.path.exists()
- vb.net - 如何有效调试异步编程中未捕获的异常?
- webpack - Webpack watch 不允许监听开放端口?
- reactjs - ReactJS useCallback 不是反应的功能吗?
- angular - MEAN 中的第 3 方 API 调用
- python - 将谷歌数据存储和大查询数据连接在一起
- javascript - reactjs中设置时间间隔的问题
- swift - 更改约束的高度值时出错