@FahadTiger - I will explain your error message. In that explanation, I SHOULD use code tags but I can't colorize them so I'll do something else.
Do While Not rs2.EOF
For j = LBound(MYarray) To UBound(MYarray)
If rs2.Fields("ISSUE").Value = MYarray(j) Then
store = store & "," & rs2.Fields("ENGINEER").Value
Else
End If
rs2.MoveNext
Loop
The
DO WHILE ... LOOP construct is almost OK - except that the
FOR loop construct is incomplete. More specifically, the
FOR J=... loop is unterminated. The correct termination would be to put a
NEXT J just below the
rs2.MoveNext instruction. You would NOT use a simple
NEXT statement because that is not the correct termination. The syntax of VBA
FOR "stepping" loops requires that you not only have the stepping variable in the
FOR statement but ALSO in the
NEXT statement.
This error is due to the "code block" concept. I colorized to show the different blocks. The
IF/THEN/ELSE/END IF block in PURPLE is perfectly legal and properly terminated (though you could omit the
ELSE and it wouldn't change anything.) This is not the cause of the problem.
The GREEN block is unterminated because of not having the
NEXT J in place. Therefore, the
LOOP statement doesn't have a corresponding
DO statement
in the same code block. My colors show what you probably intended, but using the code block concept, that
LOOP statement appears (to VBA) to be in the GREEN block even though the corresponding
DO WHILE was in the RED block. Thus, in the block where it appears, you have a
LOOP without a
DO. Adding the
NEXT J before the
LOOP statement would close out the GREEN block and leave you back in the RED block where the
LOOP would properly terminate the
DO.
Just one more side note:
rs2.Fields("ISSUE").Value is a bit torturous. You could have used
rs2![ISSUE] just as easily. Ditto for the [Engineer] field. Turns out that for anything that HAS a .Value property, it is the default property and thus does not need to be expressed. AND if that recordset has a field named ISSUE or one called ENGINEER, then the
rs2![fieldname] syntax gets you there without quite as much typing. Again, you can omit the
FIELDS() element because the default property for a recordset IS the FIELDS collection.