我在MS-Access-2007中设计了一个表单,该表单具有两个文本框SearchFor
,SrchText
和一个列表框SearchResults
。此表单用于从查询中搜索记录,并在SearchResults
中得出结果。
SearchFor
用于放置要搜索的值
SrchText
用作查询参数
SearchResults
用于显示搜索值
这段代码可以正常工作,但是当我在文本框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
答案 0 :(得分:1)
最后,我找到了解决方案,但是我仍然不知道为什么这样做。
打开表单,进入设计视图,突出显示搜索框并打开属性表。在“其他”选项卡下,有一个“允许自动更正”选项。将其设置为否,小写的“ i”终于可以使用了。