我在下面有我的代码,以查看用户是否创建了一个4位数的引脚,如果它们没有填充引脚,那么引脚将被设置为空字符串。没什么大不了。
我在下面的if
语句中对此进行了测试,但它返回了无效的null异常使用:
Dim U As String
If Me.txtUnlock = Null Then
U = 0
Else
U = Me.txtUnlock
End If
If IsNumeric(U) = False Then
MsgBox "Unlock pin only accepts numbers only.", , "Retail unlock"
Me.txtUnlock = Null
Me.txtUnlock.SetFocus
Exit Sub
End If
If Len(U) <> 4 Then
MsgBox "Retail unlock must be four digits long.", , "Retail unlock"
Me.txtUnlock.SetFocus
Exit Sub
End If
然后我检查下面的引脚是否为空:
If IsNull(Me.txtUnlock) Then
check = check + 1
UL = ""
Else
UL = Me.txtUnlock
End If
使用NZ函数考虑这个简化的代码:
Dim U As String
U = NZ(Me.txtUnlock,0)
Dim fail as Boolean
If Not IsNumeric(U) Then
MsgBox "Unlock pin only accepts numbers only.", , "Retail unlock"
fail = true
ElseIf Len(U) <> 4 Then
MsgBox "Retail unlock must be four digits long.", , "Retail unlock"
fail = true
End If
If fail then
With Me.txtUnlock
.value = vbNullString
.SetFocus
End With
End If
If Me.txtUnlock = Null Then
你不能这样做。试试:
If IsNull(Me!txtUnlock.Value) Then