Monday, April 09, 2012 6:36 PM
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
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.
- Moved by Mark Liu-lxfModerator Wednesday, April 11, 2012 5:47 AM (From:Visual Basic General)
Monday, April 09, 2012 6:44 PM
This forum is about the .Net based standalone versions of Visual Basic. Please have a look at this forum instead:
(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.
Monday, April 09, 2012 6:53 PM
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
- Edited by chipmunkofdoom2 Monday, April 09, 2012 6:54 PM
Monday, April 09, 2012 6:59 PM
- Merged by Mark Liu-lxfModerator Wednesday, April 11, 2012 5:36 AM duplicate thread
Monday, April 09, 2012 6:59 PMThanks, I posted it in the right place. Sorry I did not realize it.
Monday, April 09, 2012 7:00 PM
Thanks, it is not .NET.
I had posted in the wrong forum. My bad.
Monday, April 09, 2012 7:36 PM
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
Tuesday, April 10, 2012 5:19 PMThanks Hans that worked.