Microsoft Access - 循环遍历每个表单上的所有表单和控件 [英] Microsoft Access - Loop through all forms and controls on each form
问题描述
标签'TESTING'的唯一对象是标签,所以他们将拥有标题属性。
到目前为止,我有这个作为函数:
公共函数changelabel()
错误恢复下一个
Dim obj As AccessObject,dbs As Object
Dim ctrl as Control
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
DoCmd.OpenForm obj.Name,acDesign
For Each ctrl In Me.Controls
If ctrl.Tag =TESTING然后
ctrl.Caption =abc123
结束如果
下一个ctrl
下一个obj
End Function
然后这个按钮代码:
Public Sub TestButton_Click()
Call changelabel
End Sub
所以它执行第一个for循环并打开所有的正确地在设计视图中形成。问题在于第二个循环。没有任何标签标签的标签属性为TESTING被更改为abc123。
那么我需要更改以获得第二个for循环工作?
类似于这样的
Dim b As
Dim i As Integer
Dim c As Control
For i = 0 To CurrentProject.AllForms.Count - 1
如果不是CurrentProject.AllForms(i).IsLoaded Then
DoCmd.OpenForm CurrentProject.AllForms(i).Name,acDesign
End If
Set f = Forms(i)
For Each c In f.Controls
If c.Tag =TESTINGThen
c.Caption =TESTING
End如果
下一个c
下一个我
结束功能
您需要添加一些内务管理来将对象设置为空等。
Okay so when I press a specific button I want to loop through all forms, then find every control in each form with the tag 'TESTING'. If the tag = 'TESTING' then I want to change the caption of the object to 'abc123'.
The only objects with the tag 'TESTING' will be labels, so they will have the caption property.
So far I have this as the function:
Public Function changelabel()
On Error Resume Next
Dim obj As AccessObject, dbs As Object
Dim ctrl as Control
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
DoCmd.OpenForm obj.Name, acDesign
For Each ctrl In Me.Controls
If ctrl.Tag = "TESTING" Then
ctrl.Caption = "abc123"
End If
Next ctrl
Next obj
End Function
Then this as the button code:
Public Sub TestButton_Click()
Call changelabel
End Sub
So it executes the first for loop and opens all the forms in design view correctly. The problem lies with the second for loop. None of the label captions that have the tag property as 'TESTING' are changed to 'abc123'.
So what do I need to change to get the second for loop to work?
Something like this
Public Function changelabel()
Dim f As Form
Dim i As Integer
Dim c As Control
For i = 0 To CurrentProject.AllForms.Count - 1
If Not CurrentProject.AllForms(i).IsLoaded Then
DoCmd.OpenForm CurrentProject.AllForms(i).Name, acDesign
End If
Set f = Forms(i)
For Each c In f.Controls
If c.Tag = "TESTING" Then
c.Caption = "TESTING"
End If
Next c
Next i
End Function
You'll need to add a bit of house-keeping to set the objects used to nothing etc..
这篇关于Microsoft Access - 循环遍历每个表单上的所有表单和控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!