T
tw
the array is dimmed at the beginning of the form code like this
'***********************
Option Compare Database
Option Explicit
Dim arrUsers() As String
Dim arrGroups() As String
Dim arrGroupMembership As Variant
'***************************
the vaiables arrUsers() and arrGroups() are filled in the on load function
the function below, cmbUsers_Change(), is a combo box with the data from
arrUsers() as the rowsource for the valuelist. Upon change of a user I want
to fill two list boxes one with the groups that the user is a member of, the
other with the groups that the user is not a member of. In the two
dimensional array arrGroupMembership the first column of the array is the
group name the second column of the array is -1 if the user is a member and
0 if the user is not currently a member. The first iteration of the for
each loop works fine. Then during the second iteration of the for each loop
I get the message subscript out of range when trying to redim the array.
What am I doing wrong?
Private Sub cmbUsers_Change()
'initialize the array arrGroupMembership
'initialize the list boxes
Dim xloop
Dim xloopCount
Dim strMemberRowSource As String
Dim strAvailableRowSource As String
strMemberRowSource = ""
strAvailableRowSource = ""
xloopCount = 0
ReDim arrGroupMembership(xloopCount, 1)
For Each xloop In arrGroups
If xloopCount > 0 Then ReDim Preserve arrGroupMembership(xloopCount,
1)
'SUBSCRIPT OUT OF RANGE OCCURS on REDIM above during second iteration of
loop
arrGroupMembership(xloopCount, 0) = arrGroups(xloopCount)
If IsUserInGroup(arrGroups(xloopCount), Me.cmbUsers.Value) Then
arrGroupMembership(xloopCount, 1) = -1
If Len(strMemberRowSource) > 0 Then
strMemberRowSource = strMemberRowSource & "; " &
arrGroups(xloopCount)
Else
strMemberRowSource = arrGroups(xloopCount)
End If
Else
arrGroupMembership(xloopCount, 1) = 0
If Len(strAvailableRowSource) > 0 Then
strAvailableRowSource = strAvailableRowSource & "; " &
arrGroups(xloopCount)
Else
strAvailableRowSource = arrGroups(xloopCount)
End If
End If
xloopCount = xloopCount + 1
Next
Me.lstAvailable.RowSource = strAvailableRowSource
Me.lstMembership.RowSource = strMemberRowSource
Me.Refresh
End Sub
'***********************
Option Compare Database
Option Explicit
Dim arrUsers() As String
Dim arrGroups() As String
Dim arrGroupMembership As Variant
'***************************
the vaiables arrUsers() and arrGroups() are filled in the on load function
the function below, cmbUsers_Change(), is a combo box with the data from
arrUsers() as the rowsource for the valuelist. Upon change of a user I want
to fill two list boxes one with the groups that the user is a member of, the
other with the groups that the user is not a member of. In the two
dimensional array arrGroupMembership the first column of the array is the
group name the second column of the array is -1 if the user is a member and
0 if the user is not currently a member. The first iteration of the for
each loop works fine. Then during the second iteration of the for each loop
I get the message subscript out of range when trying to redim the array.
What am I doing wrong?
Private Sub cmbUsers_Change()
'initialize the array arrGroupMembership
'initialize the list boxes
Dim xloop
Dim xloopCount
Dim strMemberRowSource As String
Dim strAvailableRowSource As String
strMemberRowSource = ""
strAvailableRowSource = ""
xloopCount = 0
ReDim arrGroupMembership(xloopCount, 1)
For Each xloop In arrGroups
If xloopCount > 0 Then ReDim Preserve arrGroupMembership(xloopCount,
1)
'SUBSCRIPT OUT OF RANGE OCCURS on REDIM above during second iteration of
loop
arrGroupMembership(xloopCount, 0) = arrGroups(xloopCount)
If IsUserInGroup(arrGroups(xloopCount), Me.cmbUsers.Value) Then
arrGroupMembership(xloopCount, 1) = -1
If Len(strMemberRowSource) > 0 Then
strMemberRowSource = strMemberRowSource & "; " &
arrGroups(xloopCount)
Else
strMemberRowSource = arrGroups(xloopCount)
End If
Else
arrGroupMembership(xloopCount, 1) = 0
If Len(strAvailableRowSource) > 0 Then
strAvailableRowSource = strAvailableRowSource & "; " &
arrGroups(xloopCount)
Else
strAvailableRowSource = arrGroups(xloopCount)
End If
End If
xloopCount = xloopCount + 1
Next
Me.lstAvailable.RowSource = strAvailableRowSource
Me.lstMembership.RowSource = strMemberRowSource
Me.Refresh
End Sub