当我使用此按钮时出现错误,因为if,给出错误无效使用null,有人可以解释一下吗?
Sub Concluído_Click()
Dim novonome As String
Dim dataadmi As Date
Dim datanasc As Date
Dim Email As Hyperlink
Dim Cargo As String
Dim Categoria As String
Dim ingless As String
Dim inglesw As String
Dim coordeq As String
Dim relcli As String
Dim Java As String
Dim SQL As String
Dim PHP As String
Dim wserv As String
Dim Vendas As String
Dim dgraf As String
Set table = New ADODB.Recordset
With Form_Funcionários
**If Len(.Nome.value & "") = 0 Or _
ValornaColuna(.Nome.value, "Funcionários", "Nome") = True Then**
MsgBox "Campo Nome do Formulario encontra-se vazio ou ja existe! Por favor altere o seu valor!", vbOKOnly, "Campo Vazio"
End If
End With
HideAll
End Sub
Private Function ValornaColuna(ByVal value As String, ByVal formTable As String, ByVal formColumn As String) As Boolean
Dim valueToCompare As String
Dim C As Boolean
Set table = New ADODB.Recordset
table.Open formTable, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
C = False
While table.EOF = False And ExistsInColumn = False
valueToCompare = table.Fields(formColumn)
If StrComp(valueToCompare, value, vbTextCompare) = 0 Then
C = True
End If
table.MoveNext
Wend
table.Close
End Function
答案 0 :(得分:3)
这将在.Nome.value
为空时抛出错误(无效使用Null),因为ValornaColuna
需要String作为其第一个参数的数据类型。而Null不是字符串类型。
If Len(.Nome.value & "") = 0 Or _
ValornaColuna(.Nome.value, "Funcionários", "Nome") = True Then
只要Nz
为空,就可以使用.Nome.value
传入一个空字符串来避免该错误。
If Len(.Nome.value & "") = 0 Or _
ValornaColuna(Nz(.Nome.value, vbNullSting), "Funcionários", "Nome") = True Then