gpt4 book ai didi

ms-access - 尝试解决 VBA 中的 "invalid use of Null"

转载 作者:行者123 更新时间:2023-12-04 16:25:05 26 4
gpt4 key购买 nike

首先快速片段:

Dim GUID As String
Dim givenNames, familyName, preferredName, gender, comments, carer, medicareNumber, patientNumber As String
Dim dob As Variant
Dim deceased, resolved, consultNotes As Boolean
Dim age As Variant

givenNames = Null
familyName = Null
preferredName = Null
gender = Null
dob = Null
comments = Null
deceased = False
resolved = False
carer = Null
age = Null
consultNotes = False
patientNumber = Null ' This is where I get the error

知道为什么最后一个变量会绊倒吗?我已将 Null 分配给一堆其他字符串,没有任何错误。

最佳答案

在 VBA/VB6 中,字符串不能设置为 Null;只有 Variants 可以设置为 null。此外,当您像问题中一样声明内联逗号分隔的变量时,只有最后一个会被输入为字符串;所有其他的都被输入为变体。要将它们在一行中声明为一种类型,您必须包含该类型

Dim a As String, Dim b As String ...

这就是为什么只在一行中声明它们是有意义的。

(顺便说一句,应该注意的是 deceased, resolved 也出于同样的原因被输入为变体。)

关于ms-access - 尝试解决 VBA 中的 "invalid use of Null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5630743/

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