G
Guest
Hi!
I have a For Each loop in my code that cycles through values in an array,
but I'm getting a "for loop not initialized" error on it. The line that
generates the error is "For Each varArrayItem In varReqdFlds". The function
is called from inside another for each loop, which passes the variables
intApptStatus and varItem to it. The variables in the required fields list
are public and are declared at the top of the module. Any ideas?
Here's the code:
Function MissingFields(intApptStatus As Integer, varItem As Variant) As
Boolean
Dim varReqdFlds() As Variant
Dim varArrayItem As Variant
Dim intCounter As Integer
'Select the right list of required fields for this record
Select Case intApptStatus
Case Is < 4
ReDim strReqdFlds(9)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate, strDeptKey,
_ strDivAffil, strRankType, intApptStatus, strSalStatus, strWorkStatus,
strTenureCode)
Case 4
ReDim strReqdFlds(4)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate,
intApptStatus, _ strTenureCode)
Case 5
ReDim strReqdFlds(7)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate, strDeptKey,
_ strDivAffil, strRankType, intApptStatus, strEndReason)
End Select
'Test to make sure all needed fields are populated
For Each varArrayItem In varReqdFlds
If varArrayItem = "" Or IsNull(varArrayItem) Then
For intCounter = 1 To Form_CreateRankRecords.lstApproved.ListCount
Form_CreateRankRecords.lstApproved.Selected(intCounter) =
False
Next intCounter
'Select the first problem record
Form_CreateRankRecords.lstApproved.Selected(varItem) = True
MissingFields = True
GoTo exitProc
End If
Next varArrayItem
'If it gets through the previous loop without exiting, there are no
missing fields.
MissingFields = False
End Function
I have a For Each loop in my code that cycles through values in an array,
but I'm getting a "for loop not initialized" error on it. The line that
generates the error is "For Each varArrayItem In varReqdFlds". The function
is called from inside another for each loop, which passes the variables
intApptStatus and varItem to it. The variables in the required fields list
are public and are declared at the top of the module. Any ideas?
Here's the code:
Function MissingFields(intApptStatus As Integer, varItem As Variant) As
Boolean
Dim varReqdFlds() As Variant
Dim varArrayItem As Variant
Dim intCounter As Integer
'Select the right list of required fields for this record
Select Case intApptStatus
Case Is < 4
ReDim strReqdFlds(9)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate, strDeptKey,
_ strDivAffil, strRankType, intApptStatus, strSalStatus, strWorkStatus,
strTenureCode)
Case 4
ReDim strReqdFlds(4)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate,
intApptStatus, _ strTenureCode)
Case 5
ReDim strReqdFlds(7)
strReqdFlds = Array(strApptTypeDesc, dteRankEffDate, strDeptKey,
_ strDivAffil, strRankType, intApptStatus, strEndReason)
End Select
'Test to make sure all needed fields are populated
For Each varArrayItem In varReqdFlds
If varArrayItem = "" Or IsNull(varArrayItem) Then
For intCounter = 1 To Form_CreateRankRecords.lstApproved.ListCount
Form_CreateRankRecords.lstApproved.Selected(intCounter) =
False
Next intCounter
'Select the first problem record
Form_CreateRankRecords.lstApproved.Selected(varItem) = True
MissingFields = True
GoTo exitProc
End If
Next varArrayItem
'If it gets through the previous loop without exiting, there are no
missing fields.
MissingFields = False
End Function