如何通过vba验证访问表单中的输入数据

时间:2016-03-14 19:20:18

标签: vba ms-access

我尝试不允许用户输入小数值示例.238或0.123或1.4,。

我的代码到目前为止。 验证< = 8,如果不是IsNumeric,<> 12

main

3 个答案:

答案 0 :(得分:0)

只需检查字符串中的每个位置,看看它是否为数字

Public Function ValidNumericValue() As Boolean
Dim s As String
Dim i As Integer
Dim bValid as Boolean
bValid = True
'get Text value
s = txt_xampleqty

'loop through the entire string
For i = 1 To Len(s)
    'check to see if the character is a numeric one
    If IsNumeric(Mid(s, i, 1)) = False Then
        'set the return value
        bValid = False
        Exit For
    End If
Next i
ValidNumericValue = bValid
End Function

答案 1 :(得分:0)

将数字转换为整数,并查看是否具有相同的值:

If IsNumeric(Trim(txt_xampleqty)) Then
    if CLng(txt_xampleqty)<>CCurr(txt_xampleqty)
        MsgBox "You are not allowd users to entry fractional values example .238 or 0.123 or 1.4"
        Cancel = True
    End If
End If

答案 2 :(得分:0)

使用TextSearch函数搜索deciml point:

If IsNumeric(Trim(txt_xampleqty)) Then
    if InStr(txt_xampleqty,".")<Len(txt_xampleqty) Then 
        MsgBox "You are not allowd users to entry fractional values example .238 or 0.123 or 1.4"
        Cancel = True
    End If
End If