[RESOLVED] Jump to unwanted sub routine
I have this piece of code:
For x = 0 To frmOnderhoudPremies.lstFonds.ListCount - 1
If Mid(frmOnderhoudPremies.lstFonds.List(x), 144, 1) = "J" Then
frmOnderhoudPremies.lstFonds.Selected(x) = True
Else
frmOnderhoudPremies.lstFonds.Selected(x) = False
End If
Next x
When running and it comes to the line:
frmOnderhoudPremies.lstFonds.Selected(x) = True
the program jumps (unwanted) to:
Private Sub lstFonds_Click()
Why does this happen and how can i make it that this wil not happen?
Herman
Re: [RESOLVED] Jump to unwanted sub routine
Why is this thread marked resolved with no other posts nor indication of a solution?
The reason you are seeing this is because when you set the selected property that triggers the click event just like you had selected it with the mouse.
You could add some code to your click event which would look at a variable and not execute the other code in the click event under the given condition.
Re: [RESOLVED] Jump to unwanted sub routine
DataMiser,
You are right and i am sorry.
That there was no orher posts i even do not understand but that of course is not in my hands.
The rest of course is my mistake.
I changed the name of 'lstfonds' in 'lstfondstabpremie', but this did not make any differance.
Then i changed the code in:
Code:
For Z = 0 To frmOnderhoudPremies.lstFondsTabPremie.ListCount - 1
If Mid(frmOnderhoudPremies.lstFondsTabPremie.List(Z), 75, 1) = "J" Then
frmOnderhoudPremies.lstFondsTabPremie.Selected(Z) = True
End If
Next Z
The position of the "J" in the listbox was changed from 144 in 75
And this works as i should work.
The jump to sub was renamed in:
Private Sub lstFondsTabPremie_Click()
Regards,
Herman
Re: [RESOLVED] Jump to unwanted sub routine
Apparently you did not understand what I was talking about
At the top of your form code under the declarations section use something like
Code:
Dim IsProcessing as Boolean
Then in your routine that is selecting the items use something like
Code:
IsProcessing=True
For x = 0 To frmOnderhoudPremies.lstFonds.ListCount - 1
If Mid(frmOnderhoudPremies.lstFonds.List(x), 144, 1) = "J" Then
frmOnderhoudPremies.lstFonds.Selected(x) = True
Else
frmOnderhoudPremies.lstFonds.Selected(x) = False
End If
Next x
IsProcessing=False
Then in your click routine you could do something like this
Code:
Private Sub lstFonds_Click()
If IsProcessing = False Then
'code that does stuff in the click event here
End If
End Sub
This will basically turn off the click event while the loop is selecting items then turn it back on again when it is done. The click event will still fire but will not execute the code within the If block while IsProcessing var is set to true.
Re: [RESOLVED] Jump to unwanted sub routine
I indeed did not understand it, but now it is clear and i will
change my code.
Thanks