程序是这样的,一个纵栏式窗体,我想在窗体上使用一个文本框输入编号按回车来快速定位某条记录,于是在该文本框的keydown事件中写了代码:
Private Sub txt_search_KeyDown(KeyCode As Integer, Shift As Integer)
Dim searchstr As String
searchstr = Me.txt_search
If KeyCode = 13 And Not IsNull(Me.txt_search) Then
Msgbox seachstr
DoCmd.FindRecord searchstr
End If
End Sub
试了下,还是不行,
比如我要在记录里找合同号为20090402的记录,控件名是“txt_htbh”,查询文本框是“txt_search”,这个焦点是转移是这样用的吗:
Private Sub txt_search_KeyDown(KeyCode As Integer, Shift As Integer)
Dim searchstr As String
searchstr = Me.txt_search
If KeyCode = 13 And Not IsNull(Me.txt_search) Then
Me!txt_htbh.setfocus
DoCmd.FindRecord searchstr
End If
End Sub