由于数据量比较多。我们在组合框选择数据时,下拉列表会比较慢。
往往需要输入拼音首字母,然后自动筛选出该首字母下的数据。
下面示例通过输入姓名首字母,自动筛选该首字母姓名的人员
详细函数
Public Function HZPY(hzstr As String) As String Dim p0 As String, C As String, str As String Dim i As Integer, j As Integer p0 = "吖八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗" For i = 1 To Len(hzstr) C = "z" str = Mid(hzstr, i, 1) If Asc(str) > 0 Then C = str Else For j = 1 To 26 If Mid(p0, j, 1) > str Then C = Chr(95 + j) Exit For End If Next End If HZPY = HZPY + C Next End Function
在窗体中调用该函数,“S_name”为文本框名称
Private Sub S_name_Change() Dim ASCMA As Long Me.助记码 = Me.S_name.Text If Len(Nz(Me.助记码)) > 0 Then ASCMA = Asc(Me.助记码) If (ASCMA > 96 And ASCMA < 123) Or (ASCMA > 64 And ASCMA < 91) Then Me.S_name.RowSource = "SELECT S_name,id,S_age,HZPY([S_name]) AS 首字母 FROM student WHERE HZPY([S_name]) Like [Forms]![frmopen]![助记码] & '*'" Me.S_name.Dropdown Else Me.S_name.RowSource = "SELECT S_name,id,S_age,HZPY([S_name]) AS 首字母 FROM student" End If End Sub
效果图
附件下载地址:http://www.office-cn.net/thread-124097-1-1.html