支持拼音首字母的组合框函数及实例
Public Function ComboBoxKeyPress(KeyAscii As Integer) As String
'调用方法 在组合框的keypress方法中加入:
'--------------------------------------------
' If ComboBoxKeyPress(KeyAscii) <> "" Then KeyAscii = 0
'--------------------------------------------
On Error GoTo Err
Dim i As Integer
With Screen.ActiveControl
If .ControlType = acComboBox And (KeyAscii >= Asc("a") And KeyAscii <= Asc("z")) Then
'只能由组合框输入小写字母时调用
ComboBoxKeyPress = Nz(HZPY(Left(.Text, .SelStart))) & Chr(KeyAscii)
While HZPY(Left(.ItemData(i), .SelStart + 1)) <> ComboBoxKeyPress And i < .ListCount - 1
i = i + 1
Wend
If i <> .ListCount And Mid(.ItemData(i), .SelStart + 1, 1) <> Chr(KeyAscii) Then
ComboBoxKeyPress = Left(.ItemData(i), .SelStart + 1)
.Value = Null
SendKeys ComboBoxKeyPress
Else
ComboBoxKeyPress = "" '为英文时不代换,否则会进入死循环
End If
End If
End With
Exit Function
Err:
ComboBoxKeyPress = ""
End Function
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
原文:http://www.office-cn.net/BBS/dispbbs.asp?BoardID=2&ID=24443
(责任编辑:admin)
- ·Access窗体居中显示技巧
- ·Access中Tab键的使用说明【技巧】
- ·Access粘贴对象到Tab选卡上的技巧
- ·Access在窗体上显示当前记录和总记录数
- ·Access隐藏组合框的小箭头
- ·Access窗体属性表
- ·【技巧】Access选项组边框变为圆角边框
- ·Access函数me.sfmsub.form 提示子窗体
- ·Access中使用缩放对话框显示文本框文字
- ·access技巧-中文显示星期几的简单方法
- ·Access控件是否可见,可编辑,锁定的技巧
- ·根据查找窗体设定的条件筛选主窗体的数
- ·父子窗体的语法介绍
- ·access实现组合框联动详细教程
- ·Web Service在Access中的应用技巧
- ·Access窗体最大化,最小化等操作