|
-
May 26th, 2005, 01:30 PM
#1
Thread Starter
Addicted Member
For Each Statement - Need Help! {Resolved}
Hi everyone, I have a picturebox (called GridFrame) which can have any amount of checkboxes in it. During a Sub I am wanting to check each checkbox in Gridframe and see if they are check, and if so, add text to a cell.
Here is what I want to do:
VB Code:
For Each CheckBox In GridFrame
If CheckBox.Value = True Then
CellText = DetailsGrid.CellText((lRow - 2), 5)
If CellText = "" Then
CellText = CheckBox.Caption
Else
CellText = CellText & "; " & CheckBox.Caption
End If
End If
Next CheckBox
Of course this doesnt work and I get a Variable not defined error which points to CheckBox. So, if you can understand what I am trying to do, then what suggestions might anyone have on what I should do or a correct way of how I should do it using the For Each Statement. Thanx everyone for the help! =)
Last edited by epod69; May 26th, 2005 at 02:26 PM.
-
May 26th, 2005, 01:42 PM
#2
Re: For Each Statement - Need Help!
what someone showed me was, to name each checkbox as checkbox*
ie) checkbox1, checkbox2, checkbox3 etc
then use this
VB Code:
For Each ctl In Me.Controls
If ctl.Name Like "CheckBox*" Then
If checkbox.checked = true Then
'do whatever
Else
'do something else
End If
End If
Next
Last edited by kfcSmitty; May 26th, 2005 at 01:58 PM.
-
May 26th, 2005, 01:43 PM
#3
Re: For Each Statement - Need Help!
just tweaked it a bit.. let me know if it works..
the gridfram.controls may not work...
VB Code:
Dim ctl As control
For Each ctl In GridFrame.controls
If Type of ctl = checkbox Then
If ctl .Value = True Then
CellText = DetailsGrid.CellText((lRow - 2), 5)
If CellText = "" Then
CellText = ctl .Caption
Else
CellText = CellText & "; " & ctl .Caption
End If
End If
End If
Next
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 26th, 2005, 01:55 PM
#4
Thread Starter
Addicted Member
Re: For Each Statement - Need Help!
Hey, in the line 'If Type of ctl = CheckBox Then' it says: Expected Expression, and points to 'Type'. Also, there is no controls option for GridFrame (the picturebox), but I put it in anyways.....but I really can't continue with the Expected Expression error.
-
May 26th, 2005, 01:57 PM
#5
Re: For Each Statement - Need Help!
 Originally Posted by epod69
Hey, in the line 'If Type of ctl = CheckBox Then' it says: Expected Expression, and points to 'Type'. Also, there is no controls option for GridFrame (the picturebox), but I put it in anyways.....but I really can't continue with the Expected Expression error.
Thats because TypeOf is one word.
-
May 26th, 2005, 02:10 PM
#6
Thread Starter
Addicted Member
Re: For Each Statement - Need Help!
GridFrame.Controls does not work =( , what am I missing?
-
May 26th, 2005, 02:12 PM
#7
Re: For Each Statement - Need Help!
[LGS]Static is on the right track, however a picture box doesn't have a Controls collection and you can't use the equal sign with the TypeOf keyword. You must use the Is keyword instead. So you need to use code simular to this:
VB Code:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is CheckBox Then
If ctl.Container Is GridFrame Then
If ctl.Value = vbChecked Then
CellText = DetailsGrid.CellText((lRow - 2), 5)
If CellText = "" Then
CellText = ctl.Caption
Else
CellText = CellText & "; " & ctl.Caption
End If
End If
End If
End If
Next
-
May 26th, 2005, 02:25 PM
#8
Thread Starter
Addicted Member
Re: For Each Statement - Need Help!
Thanx a lot, that last one worked good. Thanx everyone for the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|