VBA 访问 - 文本框值到字符串

VBA Access - TextBox Value to String

我正在尝试将文本框的值读取为字符串并检查它是否为空:

Dim dataFileName as String

dataFileName = Text0.Value

If dataFileName = "" Then
End If

这在进行分配时会因 "Invalid use of Null" 而崩溃。我怎样才能做到这一点?

有一种或多种方法可以对此进行测试。

这里有两种方法,

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

另一种方法是将其声明为字符串,但要确保传递的字符串不是 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