欢 迎 光 临 数据载入中,请稍候......'s BLog
数据载入中,请稍候......
这就是我
数据载入中,请稍候......
用户登陆
数据载入中,请稍候......
最新公告
数据载入中,请稍候......
站点日历
数据载入中,请稍候......
最新日志
数据载入中,请稍候......
最新回复
数据载入中,请稍候......
最新留言
数据载入中,请稍候......
 日志搜索

友情链接
其他信息


·[荐]access超好用的智能文本框通用函数     -|cloudy 发表于 2008-8-22 8:35:00

时 间:2008-8-21 21:47:12
作 者:Trynew
摘 要:为了庆祝奥运开幕,特推出最新特价的“超好用的智能文本框通用函数”例程。

正 文:

原文地址:http://www.accessbbs.cn/bbs/viewthread.php?tid=14166&extra=&page=1

功能:
1、用法简单,任何文本框、组合框的“键释放”事件中使用此函数,即可带有智能辅助和选择录入此字段已有的记录中的文本。
2、极大加块了录入速度,比组合框快X倍。
3、价格公道,绝对原创,如有假冒,买一赔十。

代码:
Public Function GetFieldValue(Optional KeyCode As Integer = 1000)
'MsgBox KeyCode
On Error Resume Next
If KeyCode = 8 or KeyCode = 46 Then Exit Function
Dim i As Integer, txtSet As TextBox, intMax As Integer
Set txtSet = Screen.ActiveControl
i = txtSet.SelStart
If KeyCode = 40 Then
    With Screen.ActiveForm.RecordsetClone
    Do While Not .EOF()
        .MoveNext
        If Left(.Fields(txtSet.ControlSource), i) = Left(txtSet.Text, i) Then
            txtSet.Text = .Fields(txtSet.ControlSource)
            txtSet.Tag = txtSet.Text
            txtSet.SelStart = i
            txtSet.SelLength = Len(txtSet.Text)
            Exit Do
        End If
        intMax = intMax + 1
        If intMax > 10000 Then Exit Do
    Loop
    End With
    Exit Function
End If
If KeyCode = 38 Then
    With Screen.ActiveForm.RecordsetClone
    Do While Not .BOF()
        .MovePrevious
        If Left(.Fields(txtSet.ControlSource), i) = Left(txtSet.Text, i) Then
            txtSet.Text = .Fields(txtSet.ControlSource)
            txtSet.Tag = txtSet.Text
            txtSet.SelStart = i
            txtSet.SelLength = Len(txtSet.Text)
            Exit Do
        End If
        intMax = intMax + 1
        If intMax > 10000 Then Exit Do
    Loop
    End With
    Exit Function
End If
If txtSet.SelStart = Len(txtSet.Text) Then
    If Left(Nz(txtSet.Tag), i) = txtSet.Text Then
        txtSet.Text = txtSet.Tag
        txtSet.SelStart = i
        txtSet.SelLength = Len(txtSet.Text)
    Else
        With Screen.ActiveForm.RecordsetClone
        .MoveFirst
        Do While Not .EOF()
            If Left(.Fields(txtSet.ControlSource), i) = txtSet.Text Then
                txtSet.Text = .Fields(txtSet.ControlSource)
                txtSet.Tag = txtSet.Text
                txtSet.SelStart = i
                txtSet.SelLength = Len(txtSet.Text)
                Exit Do
            End If
           intMax = intMax + 1
            If intMax > 10000 Then Exit Do
            .MoveNext
        Loop
        End With
    End If
End If
End Function

用法:
在“键释放”事件中使用
Private Sub 姓名_KeyUp(KeyCode As Integer, Shift As Integer)
GetFieldValue KeyCode
End Sub

智能文本框:你可以在新记录的姓名字段中,输入“李”字,则字段中会自动出现反黑选定的“应”字,你可以用上下键更换此表已有姓名中的其它候选名字,也可以继续输入,或者回车(TAB)键转到其他字段。此函数有一个可选参数,放在“键释放”事件中,不带参数则屏蔽上下键选择功能。

500)this.width=500}" alt="" src="http://www.accessoft.com/images/download.gif" border=0>点击下载此附件


[阅读全文 | 回复(0) | 引用通告 | 编辑]

  • 标签:access 
  • 发表评论:
    数据载入中,请稍候......