Respondido VB 7 Looping thru Controls

  • segunda-feira, 9 de abril de 2012 18:36
     
     

    I am running Win 7 (64-bit) with Office 2010 (VB 7).

    I have some code that loops thru all controls in a form and does some stuff. 

    This was working fine in XP with Office 2007. 

    This code now throws type mismatch error at the For each.... line. 

        For Each ctlControl In Controls
            If TypeName(ctlControl) = "CheckBox" Then
                If ctlControl.Name <> chkAll.Name Then
                    If ctlControl.Value = True Then
                        Call doProc(ctlControl.Caption)
                    End If
                End If
            End If
        Next ctlControl

    I have not included any dependencies except remove DAO and added Microsoft Access 14.0 Object Library.

    I am at a loss to understand why this would not work. Any help would be greatly appreciated. 

    Thanks.

Todas as Respostas

  • segunda-feira, 9 de abril de 2012 18:44
     
     Resposta Proposta

    This forum is about the .Net based standalone versions of Visual Basic. Please have a look at this forum instead:
    http://social.msdn.microsoft.com/Forums/en-US/worddev/threads

    (I think there you should also mention how ctlControl is declared. If it's CheckBox, if fails if there are not only checkboxes on the Form)

    EDIT: Sorry, doesn't have to be Word. Can be any other Office product, too, but I think you find it from the given link.


    Armin


  • segunda-feira, 9 de abril de 2012 18:53
     
      Contém Código

    If you were looking for a .Net solution:

            For Each FormControl As Control In Me.Controls
                If TypeOf (FormControl) Is CheckBox Then
                    If Not (FormControl.Name = chkAll.Name) Then
                        If DirectCast(FormControl, CheckBox).Checked = True Then
                            'Do Your Stuff Here
                        End If
                    End If
                End If
            Next


  • segunda-feira, 9 de abril de 2012 18:59
     
     

    I am running Win 7 (64-bit) with Office 2010 (VB 7).

    I have some code that loops thru all controls in a form and does some stuff. 

    This was working fine in XP with Office 2007. 

    This code now throws type mismatch error at the For each.... line. 

    Dim ctlControl As Control

        For Each ctlControl In Controls
            If TypeName(ctlControl) = "CheckBox" Then
                If ctlControl.Name <> chkAll.Name Then
                    If ctlControl.Value = True Then
                        Call doProc(ctlControl.Caption)
                    End If
                End If
            End If
        Next ctlControl

    I have not included any dependencies except remove DAO and added Microsoft Access 14.0 Object Library.

    I am at a loss to understand why this would not work. Any help would be greatly appreciated. 

    Thanks.

  • segunda-feira, 9 de abril de 2012 18:59
     
     
    Thanks, I posted it in the right place. Sorry I did not realize it.
  • segunda-feira, 9 de abril de 2012 19:00
     
     

    Thanks, it is not .NET.

    I had posted in the wrong forum. My bad.

  • segunda-feira, 9 de abril de 2012 19:36
     
     Respondido Contém Código

    The declaration ... As Control has become ambiguous because Control is a Forms object, but also an Access object.

    To remove the ambiguity, declare ctlControl as follows:

    Dim ctlControl As MSForms.Control


    Regards, Hans Vogelaar

    • Sugerido como Resposta Mark Liu-lxfModerator quarta-feira, 11 de abril de 2012 05:37
    • Marcado como Resposta Tinausa quarta-feira, 11 de abril de 2012 10:45
    •  
  • terça-feira, 10 de abril de 2012 17:19
     
     
    Thanks Hans that worked.