Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    19

    Unanswered: Set fields to Null on resize

    I have a form that is minimized when a report runs. On closing the report the form is set on its Resize option to follow the code below:
    Code:
    Private Sub Form_Resize()
    Me.Combo6.Requery
        Me.Combo6.Value = Null
        Me.Combo53.Requery
        Me.Combo53.Value = Null
    End Sub
    As I have a number of combo boxes that I want to set to Null, is there a shorter code I can use that will do the same as following the above sequence for all my Combo boxes?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Dim ctl as Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acComboBox Then
            ctl.Requery
            ctl.Value = Null
        End If
    Next ctl
    This implies that every combobox must be handled in the same way. If it's not the case, you can "mark" the comboboxes that must be processed in the loop by using their Tag property, for instance:
    Code:
    Dim ctl as Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acComboBox And ctl.Tag = "HandleMe" Then
            ctl.Requery
            ctl.Value = Null
        End If
    Next ctl
    If the Tag property is already used for any other purpose, you can also use the HelpContextID property. Normally it is used in relation with a custom compiled help file but actually almost nobody writes and compiles their own help files, (noone that I know does it anyway):
    Code:
    Dim ctl as Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acComboBox Then
        '
        ' Cannot test both on the same line because not every control has a HelpContextID property.
        '
            If ctl.HelpContextId = -1 Then
                ctl.Requery
                ctl.Value = Null
            End If
        End If
    Next ctl
    Have a nice day!

  3. #3
    Join Date
    Aug 2011
    Posts
    19

    Set fields to Null on resize

    I went with the first option that works great. Thanks

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome !
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •