我的应用程序中有一个 Sub,当前位于名为 FRMPFC_folderCreatorWindow 的用户窗体中。为了清楚整个应用程序,我希望将此 Sub 从用户窗体移动到名为 PFC_filesystemManipulation 的模块中,并通过 FRMPFC_folderCreatorWindow 中的按钮从那里调用 Sub 但是,当我这样做并运行我的代码时,会在该行生成错误:
For Each cCont In Me.Controls
我知道这是因为 Sub 已脱离表单的上下文,但是如何在不使用 Me.Controls 的情况下维护上下文?我猜我需要引用表单并使用 FRMPFC_folderCreatorWindow.Controls 但由于大多数控件嵌套在框架内,我不确定我当前的代码是作用于表单还是仅作用于按钮所在的框架。任何帮助将非常感激。
Private Sub PFC_createFolders(Basepath, currentControl, parentFolder, parentGroup)
Dim cCont As Control
Dim createSubFolder As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
'Check if the project folder already exists and if so, raise an error and exit
MkDir Basepath & "\" & parentFolder
'Create the superceded documents folder in every 2nd generation folder
MkDir Basepath & "\" & parentFolder & "\" & "_Old versions"
For Each cCont In Me.Controls
If TypeName(cCont) = "CheckBox" Then
If cCont.GroupName = parentGroup Then
If cCont.Value = True Then
If cCont.Name <> currentControl Then
createSubFolder = cCont.Caption
NewFolder = Basepath & "\" & parentFolder & "\" & createSubFolder
If fs.folderexists(NewFolder) Then
'do nothing
Else
'Create 3rd generation folder
MkDir NewFolder
'Create the superceded documents folder in every 3rd generation folder
MkDir NewFolder & "\" & "_Old versions"
'Create hard-coded subfolders within Confirmit Exports
If createSubFolder = "Confirmit Exports" Then
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Triple S"
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Word Export"
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Survey Definition"
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Data"
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Data" & "\" & "Early Data"
MkDir Basepath & "\" & parentFolder & "\" & createSubFolder & "\Data" & "\" & "Final Data"
End If
End If
End If
End If
End If
End If
Next cCont
End Sub