gpt4 book ai didi

ms-access - 无效使用 null Access-VBA

转载 作者:行者123 更新时间:2023-12-04 04:33:10 27 4
gpt4 key购买 nike

我在使用这个按钮时遇到错误,因为如果,给出错误无效使用 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

最佳答案

每当 .Nome.value 时,这都会抛出错误(无效使用 Null)为空,因为 ValornaColuna需要 String 作为其第一个参数的数据类型。而且 Null 不是 String 类型。

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

关于ms-access - 无效使用 null Access-VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com