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.
- Movido Mark Liu-lxfModerator quarta-feira, 11 de abril de 2012 05:47 (From:Visual Basic General)
Todas as Respostas
-
segunda-feira, 9 de abril de 2012 18:44
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
- Editado Armin Zingler segunda-feira, 9 de abril de 2012 18:45
- Sugerido como Resposta Frank L. SmithMicrosoft Community Contributor segunda-feira, 9 de abril de 2012 18:52
-
segunda-feira, 9 de abril de 2012 18:53
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
- Editado chipmunkofdoom2 segunda-feira, 9 de abril de 2012 18:54
-
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 ctlControlI 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.
- Mesclado Mark Liu-lxfModerator quarta-feira, 11 de abril de 2012 05:36 duplicate thread
-
segunda-feira, 9 de abril de 2012 18:59Thanks, 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
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:19Thanks Hans that worked.

