VBA访问 - TextBox值到字符串

时间:2015-01-20 12:30:59

标签: vba access-vba

我试图将字符串的值读取为字符串并检查它是否为空:

Dim dataFileName as String

dataFileName = Text0.Value

If dataFileName = "" Then
End If

这与"无效使用Null"崩溃在进行作业时。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

有一种或多种方法可以测试它。

以下是两种方式,

Dim dataFileName
dataFileName = Me.Text0

If IsNull(dataFileName) Then
'Or If Len(dataFileName & vbNullString) = 0 Then
    MsgBox "It is a Variant Type, but is Null"
Else
    MsgBox "It is a Variant Type, but is not Null"
End If

另一种方法是将其声明为String,但要确保传递String而不是Null

Dim dataFileName As String
dataFileName = Me.Text0 & vbNullString
'Or dataFileName = Nz(Me.Text0, vbNullString)

If Len(dataFileName) = 0 Then
    MsgBox "It is a String Type but is a NullString, but NOT NULL"
Else
    MsgBox "It is a String Type, it is not 'empty' persay."
End If