MS Access VBA中的循环

问题描述 投票:0回答:1

我在MS访问中有一个简单的VBA,由一个将填充空白字段的按钮触发。代码正在工作,但是我想知道如何重复操作,直到填充所有空白字段。我可以使用简单的VBA,但是我仍然需要学习循环和其他复杂的代码。我希望有人能帮助或启发我循环的工作原理。以下是我的VBA。

If Me.Team = "GSAP Accounts" Then
    If Me.Mantainer_Status = "Completed" Then

        If IsNull(Me.Line_Items) Then
        If Me.Line_Item_Passed_After_Validation < Me.Total_Line_Items_Raised Then
                Me.Line_Items = Me.Total_Line_Items_Raised.Value
            Else
                Me.Line_Items = Me.Line_Item_Passed_After_Validation.Value

                Forms!KPIREFRESH.Requery


        End If
        End If
    End If
End If
loops ms-access access-vba
1个回答
0
投票
Private Function FillNullFields()

Dim FormControls as Control 'Can be any Var name you want

'This will Loop Through EVERY control including Buttons / labels / and such
'So it's important to check the Control Type.
For Each FormControls in Me.Controls 

'In here you can Specify the control types you want checked
Select Case FormControls.ControlType 

   Case is = acTextBox 
     If isnull(FormControls) then 
       Formcontrols = "[Your Values here]"
     End If
'You can grab everything that the control has even if it's not listed after the [.]
'VBA just won't show it to you since it still doesn't know what the Control Actually 
'have.
'Example
'FormControls.Enabled = True 'This won't show up in the Editor but it would run it

End Select

Next FormControls

End Sub

[Basically For Loops用于循环有限次数,因此您可以使用整数来指定它,在这种情况下,我们要求VBA循环遍历窗体中的所有可用控件。

© www.soinside.com 2019 - 2024. All rights reserved.