【问题标题】:Loop to populate blank fields循环填充空白字段
【发布时间】:2019-12-19 07:02:35
【问题描述】:

我在 MS Access 中有 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

【问题讨论】:

  • For Each ctl In frm.Controls [next line>] If ctl.ControlType = acTextBox Then do_your_thing Endif Next ctl
  • 有很多关于这个主题的教程。你对循环结构到底有什么不了解的地方?

标签: vba loops ms-access


【解决方案1】:
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

基本上 For 循环用于循环有限次,因此您可以使用整数来指定它,在这种情况下,我们要求 VBA 循环浏览表单中的所有可用控件。

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多