Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    85

    Unanswered: exclude a control from Me.Control

    Can some one tell me if there is a way to exclude a control from this statement

    'Loop through each control on the form to get its value.
    For Each ctl In Me.Controls
    With ctl
    Select Case .ControlType
    Case acTextBox
    .SetFocus

    I tried the following, it did not work

    For Each ctl In Me.Controls
    where Me.Controls <> txtfrom
    With ctl
    Select Case .ControlType
    Case acTextBox
    .SetFocus
    Thanks Tim

  2. #2
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267
    One way would be to check the name property of the control (close to what you tried):

    If ctl.Name = "NameofControlYouAreLookingFor" then
    'do something
    Else
    'don't do something
    End If

    Make sure to use ctl as that will be the control you can reference when looping through all the controls.

    C

  3. #3
    Join Date
    May 2009
    Posts
    41
    Similar to what's already been mentioned, you can try this...

    Code:
        Dim ctl As Object
        For Each ctl In Me.Form.Controls
            If TypeOf ctl Is TextBox Then
                If ctl.Name <> "txtName" Then
                    ' Your code here
                End If
            ElseIf TypeOf ctl Is ComboBox Then
                If ctl.Name <> "cmbName1" And ctl.Name <> "cmbName2" Then
                    ' Your code here
                End If
            End If
        Next

  4. #4
    Join Date
    Mar 2006
    Posts
    163
    Tim

    Doesn't your code already exclude controls within the loop when you use ControlType?

    I don't think you can loop through a subset of all the controls on a form in Access VBA.

  5. #5
    Join Date
    Apr 2009
    Posts
    85
    Thanks everyone, this helped clear up my confusion. I'm new to this, have my beginning books in vb and sql, but even these basic things still fogy. Tim

Posting Permissions

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