在Access中可以用掩码方便地把字段定义为各种形式,在VB中有没有象这样设置掩码的东西?
如果没有,那么怎样规定一个text只能输入字母?
(数字、日期、字符呢?)

解决方案 »

  1.   

    sub text1_change()
    if lcase(text1.text) like [!a-z] then
    '出现非字母....
    end if
    end sub
      

  2.   

    Option ExplicitPrivate Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 8 Then Exit Sub
        If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(Chr(KeyAscii))) > 0 Then Exit Sub
        KeyAscii = 0
    End Sub
      

  3.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        if not(keyascii>=asc("a") And Keyascii<=asc("z"))then
              if not ((keyascii>=asc("A") And Keyascii<=asc("Z")) Or keyascii=vbKeyBack) then
                   keyascii=0
              endif
        endif
    End Sub