Arrays MS Access VBA使用ReDim Preserve在需要时增加数组的大小(如在按钮单击事件处理程序方法中或在循环中)

Arrays MS Access VBA使用ReDim Preserve在需要时增加数组的大小(如在按钮单击事件处理程序方法中或在循环中),arrays,vba,ms-access,dimensions,Arrays,Vba,Ms Access,Dimensions,我是Microsoft Office Professional Plus 2013 Access的新手 我正在使用以下工具开发应用程序: -Microsoft Office Professional Plus 2013 Access 在我的VBA编辑器中,我有以下类模块: Option Explicit Option Compare Database Private cntrollingPersonFullNameProp As String Private cntrollingPersonI

我是Microsoft Office Professional Plus 2013 Access的新手

我正在使用以下工具开发应用程序:

-Microsoft Office Professional Plus 2013 Access

在我的VBA编辑器中,我有以下类模块:

Option Explicit
Option Compare Database

Private cntrollingPersonFullNameProp As String
Private cntrollingPersonIsNameAddressProvidedProp As String
Private cntrollingPersonIsDOBProvidedProp As String
Private cntrollingPersonIsTaxResidenceProvidedProp As String
Private cntrollingPersonIsControllingPersonTypeProvidedProp As String
Private cntrollingPersonIsSignedAndDatedProp As String

Public Property Get CntrollingPersonFullName() As String
    CntrollingPersonFullName = cntrollingPersonFullNameProp
End Property

Public Property Let CntrollingPersonFullName(lCntrollingPersonFullName As String)
    cntrollingPersonFullNameProp = lCntrollingPersonFullName
End Property

Public Property Get CntrollingPersonIsNameAddressProvided() As String
    CntrollingPersonIsNameAddressProvided = cntrollingPersonIsNameAddressProvidedProp
End Property

Public Property Let CntrollingPersonIsNameAddressProvided(lCntrollingPersonIsNameAddressProvided As String)
    cntrollingPersonIsNameAddressProvidedProp = lCntrollingPersonIsNameAddressProvided
End Property

Public Property Get CntrollingPersonIsDOBProvided() As String
    CntrollingPersonIsDOBProvided = cntrollingPersonIsDOBProvidedProp
End Property

Public Property Let CntrollingPersonIsDOBProvided(lCntrollingPersonIsDOBProvided As String)
    cntrollingPersonIsDOBProvidedProp = lCntrollingPersonIsDOBProvided
End Property

Public Property Get CntrollingPersonIsTaxResidenceProvided() As String
    CntrollingPersonIsTaxResidenceProvided = cntrollingPersonIsTaxResidenceProvidedProp
End Property

Public Property Let CntrollingPersonIsTaxResidenceProvided(lCntrollingPersonIsTaxResidenceProvided As String)
    cntrollingPersonIsTaxResidenceProvidedProp = lCntrollingPersonIsTaxResidenceProvided
End Property

Public Property Get CntrollingPersonIsControllingPersonTypeProvided() As String
    CntrollingPersonIsControllingPersonTypeProvided = cntrollingPersonIsControllingPersonTypeProvidedProp
End Property

Public Property Let CntrollingPersonIsControllingPersonTypeProvided(lCntrollingPersonIsControllingPersonTypeProvided As String)
    cntrollingPersonIsControllingPersonTypeProvidedProp = lCntrollingPersonIsControllingPersonTypeProvided
End Property

Public Property Get CntrollingPersonIsSignedAndDated() As String
    CntrollingPersonIsSignedAndDated = cntrollingPersonIsSignedAndDatedProp
End Property

Public Property Let CntrollingPersonIsSignedAndDated(lCntrollingPersonIsSignedAndDated As String)
    cntrollingPersonIsSignedAndDatedProp = lCntrollingPersonIsSignedAndDated
End Property
在表单代码文件中

Dim cntrollingPersonsArray()  As CntrollingPerson


Private Sub AddControllingPersonBtn_Click()
     Dim cntrlPerson As New CntrollingPerson
    cntrlPerson.CntrollingPersonFullName =  …….
    cntrlPerson.CntrollingPersonIsNameAddressProvided =  …..

  ReDim Preserve cntrollingPersonsArray(UBound(cntrollingPersonsArray)+ 1)   
cntrollingPersonsArray(UBound(cntrollingPersonsArray)) = cntrlPerson 

 End Sub
应用程序抛出以下命令:

“91”对象变量或未设置块变量

在下一行

cntrollingPersonsArray(UBound(cntrollingPersonsArray)) = cntrlPerson
我尝试了一系列不同的代码修改

ReDim Preserve cntrollingPersonsArray(UBound(cntrollingPersonsArray))


有人能告诉我采取什么步骤来纠正上述问题吗?

使用集合对象而不是数组。你所有的问题都解决了

例如:

Option Explicit

Private cntrollingPersons As New Collection

Private Sub AddControllingPersonBtn_Click()
    Dim cntrlPerson As New CntrollingPerson
    cntrlPerson.CntrollingPersonFullName = ""
    cntrlPerson.CntrollingPersonIsNameAddressProvided = ""

    cntrollingPersons.Add cntrlPerson
End Sub

相关阅读:

使用集合对象而不是数组。你所有的问题都解决了

例如:

Option Explicit

Private cntrollingPersons As New Collection

Private Sub AddControllingPersonBtn_Click()
    Dim cntrlPerson As New CntrollingPerson
    cntrlPerson.CntrollingPersonFullName = ""
    cntrlPerson.CntrollingPersonIsNameAddressProvided = ""

    cntrollingPersons.Add cntrlPerson
End Sub

相关阅读:

在分配objectRule of thumb时使用Set,如果不知道最终会有多少项,请不要使用数组。在循环中保留ReDim效率低下!为什么要贴标签?更糟糕的是,为什么没人去看标签呢?对不起,我对MS Access很幼稚。MS Access的VBA编辑器不是VBScript还是Visual Basic?对不起,就像我说的,我是MS Access的新手在分配objectRule时使用Set经验法则,如果不知道最终将有多少项,请不要使用数组。在循环中保留ReDim效率低下!为什么要贴标签?更糟糕的是,为什么没人去看标签呢?对不起,我对MS Access很幼稚。MS Access的VBA编辑器不是VBScript还是Visual Basic?对不起,就像我说的,我是MS Access的新手
Option Explicit

Private cntrollingPersons As New Collection

Private Sub AddControllingPersonBtn_Click()
    Dim cntrlPerson As New CntrollingPerson
    cntrlPerson.CntrollingPersonFullName = ""
    cntrlPerson.CntrollingPersonIsNameAddressProvided = ""

    cntrollingPersons.Add cntrlPerson
End Sub