I usually find an answer to problems on this forum in a matter of minutes searching, but this one I can't.
Can anyone shed light on why the For-Next loop in the following code cycles through twice?
ctl refers to a form ListBox with 1 (yes I've checked) item selected, but the Debug statement produces the same ListIndex number twice when run ... eg
5
5
or
10
10
The function RemMsgParse is definitely being called twice. Is there some peculiar quirk to ItemsSelected where it contains at least of 2 values? Or is there a special way it needs to be treated in a For-Each-Next statement?
Entire function below:
Can anyone shed light on why the For-Next loop in the following code cycles through twice?
Code:
For Each lstitem In ctl.ItemsSelected
Debug.Print ctl.ListIndex
MsgPresentCheck = MsgPresentCheck & RemMsgParse(ctl.ItemData(lstitem), "MsgCollect")
Next lstitem
ctl refers to a form ListBox with 1 (yes I've checked) item selected, but the Debug statement produces the same ListIndex number twice when run ... eg
5
5
or
10
10
The function RemMsgParse is definitely being called twice. Is there some peculiar quirk to ItemsSelected where it contains at least of 2 values? Or is there a special way it needs to be treated in a For-Each-Next statement?
Entire function below:
Code:
Public Function SetSelectedMsgsForPreview()
Dim Form As Form, ctl As Control
Dim lstitem, MsgPresentCheck
Call RemMsgClean
Set Form = Forms!MAIN_MANACC_RemittanceMsgs
Set ctl = Form!Clients_lst
lstitem = Null
MsgPresentCheck = Null
For Each lstitem In ctl.ItemsSelected
MsgPresentCheck = MsgPresentCheck & RemMsgParse(ctl.ItemData(lstitem), "MsgCollect")
Debug.Print ctl.ListIndex
Next lstitem
If IsNull(MsgPresentCheck) Then
SetSelectedMsgsForPreview = "none"
End If
End Function