试图获取远程项目中表单模块的代码行
Trying to get to the code lines of a form's module in a remote project
我正在尝试列出远程 MS Access 项目中所有过程的代码行。标准或 class 模块没有问题,但是当我进入表单时,我无法访问它们的模块属性。
Public Sub TestFrms(MyDataBaseFullName)
'MyDataBaseFullName should be a valid full name (Path & Name)
'of an MS Access DataBase mdb or accdb local file
Dim appAccess As Access.Application
Dim xObj As AccessObject
Dim xFrm As Form
Dim xMdl As Module
Dim i As Long
On Error GoTo Error
Set appAccess = New Access.Application
Call appAccess.OpenCurrentDatabase(MyDataBaseFullName)
For Each xObj In appAccess.CurrentProject.AllForms
For i = 0 To appAccess.CurrentProject.AllForms.Count - 1
'Here I am trying to get to the forms module
'because I want to lit all its code lines
'I think understand that the AllForms property does not contain
'a list of all the Forms objects but only a collection of AccessObject
'but is there a way to get to the Form's module?
'Assuming AllForms contains a collection of forms
'this next line should work and I could get to the
'Code Lines of each procedure in that module
'' Set xMdl = appAccess.CurrentProject.AllForms(i).Module
Next i
Next
NormalEnding:
'Fermer la base de données
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
Set xObj = Nothing
Exit Sub
Error:
'Aviser l'utilisateur
Call MsgBox("Error " & Err.Number & " (" & Err.Description & ")", vbCritical)
GoTo NormalEnding
End Sub
要获取表单的模块,您需要在设计视图中打开表单。
For Each xObj In appAccess.CurrentProject.AllForms
appAccess.DoCmd.OpenForm xObj.Name, 1 '1 = acDesign
Debug.Print appAccess.Forms(xObj.Name).Module.Lines(1, 10000) 'Print the first 10K lines
'If you want to print all lines with no maximum, use `Module.CountOfLines` to get the count
appAccess.DoCmd.Close 2, xObj.Name '2 = acForm
Next
我正在尝试列出远程 MS Access 项目中所有过程的代码行。标准或 class 模块没有问题,但是当我进入表单时,我无法访问它们的模块属性。
Public Sub TestFrms(MyDataBaseFullName)
'MyDataBaseFullName should be a valid full name (Path & Name)
'of an MS Access DataBase mdb or accdb local file
Dim appAccess As Access.Application
Dim xObj As AccessObject
Dim xFrm As Form
Dim xMdl As Module
Dim i As Long
On Error GoTo Error
Set appAccess = New Access.Application
Call appAccess.OpenCurrentDatabase(MyDataBaseFullName)
For Each xObj In appAccess.CurrentProject.AllForms
For i = 0 To appAccess.CurrentProject.AllForms.Count - 1
'Here I am trying to get to the forms module
'because I want to lit all its code lines
'I think understand that the AllForms property does not contain
'a list of all the Forms objects but only a collection of AccessObject
'but is there a way to get to the Form's module?
'Assuming AllForms contains a collection of forms
'this next line should work and I could get to the
'Code Lines of each procedure in that module
'' Set xMdl = appAccess.CurrentProject.AllForms(i).Module
Next i
Next
NormalEnding:
'Fermer la base de données
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
Set xObj = Nothing
Exit Sub
Error:
'Aviser l'utilisateur
Call MsgBox("Error " & Err.Number & " (" & Err.Description & ")", vbCritical)
GoTo NormalEnding
End Sub
要获取表单的模块,您需要在设计视图中打开表单。
For Each xObj In appAccess.CurrentProject.AllForms
appAccess.DoCmd.OpenForm xObj.Name, 1 '1 = acDesign
Debug.Print appAccess.Forms(xObj.Name).Module.Lines(1, 10000) 'Print the first 10K lines
'If you want to print all lines with no maximum, use `Module.CountOfLines` to get the count
appAccess.DoCmd.Close 2, xObj.Name '2 = acForm
Next