Using arrays with checkboxes (1 Viewer)

fpendino

Registered User.
Local time
Yesterday, 23:57
Joined
Jun 6, 2001
Messages
73
I am trying to cycle through some checkboxes on a form. I can't quite figure out the right code. Here is what I have.

Private Sub chkSnap0_AfterUpdate()
Dim intchk As Integer
Dim rpt As CheckBox
Dim strrpt(6) As String

If chkSnap0 = -1 Then
For intchk = 1 To 6
strrpt(intchk) = "chksnap" & intchk
rpt = strrpt(intchk)
Next intchk
End If

End Sub


Thanks for any Help!!
 

fpendino

Registered User.
Local time
Yesterday, 23:57
Joined
Jun 6, 2001
Messages
73
Does anyone know if this is possible?
 

WayneRyan

AWF VIP
Local time
Today, 05:57
Joined
Nov 19, 2002
Messages
7,122
fpendino,

This will count how many textboxes are true.

Code:
Dim ctr As Integer
ctr = 0

For Each ctl In Me.Controls
  If ctl.ControlType = acCheckBox Then
    If (ctl.Value = -1) Then
       ctr = ctr + 1
    End If
  End If
  Next

Wayne
 

fpendino

Registered User.
Local time
Yesterday, 23:57
Joined
Jun 6, 2001
Messages
73
I appreciate the reply. That wasn't necessarily what I was trying to do, but I did figure it out. Basically, I was trying to change the properties of some check boxes in an array, when one of the boxes was checked. Here's what I came up with for anyone else that may be interested.

Private Sub chkSnap0_AfterUpdate()
Dim intchk As Integer
Dim rpt(6) As CheckBox

Set rpt(1) = chkSnap1
Set rpt(2) = chkSnap2
Set rpt(3) = chkSnap3
Set rpt(4) = chkSnap4
Set rpt(5) = chkSnap5
Set rpt(6) = chkSnap6

If chkSnap0 = -1 Then
For intchk = 1 To 6
With rpt(intchk)
.Enabled = True
.Value = -1
End With
Next intchk
Else
For intchk = 1 To 6
With rpt(intchk)
.Enabled = False
.Value = 0
End With
Next intchk
End If

End Sub

Thanks!! Frank
 

Users who are viewing this thread

Top Bottom