首页 > 解决方案 > 运行时错误“2110”:`Microsoft Office Access 无法将焦点移至控件

问题描述

我在 MS-Access-2007 中设计了一个表单,它有两个 textboxSearchForSrchText一个 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

标签: ms-accessvba

解决方案


最后,我找到了解决方案,但我仍然不知道为什么会这样。

打开表单,进入设计视图,突出显示搜索框并打开属性表。在“其他”选项卡下,有一个“允许自动更正”选项。将其设置为“否”,小写“i”终于可以工作了。


推荐阅读