Form Activated Event Going in multiple loops

hi!
I have a form called frmContact which performs the following operations on its activated event. I have noticed that everytime the llOpenClose=true, the form runs correctly. however when the MsgBox loop ie the else loop is executed, the form keeps on iterating in the activated event again and again. When I run it in debug mode, i made about 15 iterations through the same loop. In normal run mode however, it flickers for 1-2 seconds and then shows up suggesting that it might be iterating then too. Is there anything that I am missing here  Every call to MsgBox and Me.Focus causes it to go back to start of the sub. However it does find llLoaded = true and goes to the CenterForm in the successive loops. but I cannot understand why it is looping through the sub.



Private Sub frmContact_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated

        If llLoaded = False Then
            llLoaded = True
            'Only going to close the form if all the Auto Add Contacts found
            If llAutoAddStatus = True Then
                If llOpenClose = True Then
                   Call AllDone()
                End If
            Else
                MsgBox("Not able to Auto Populate the specified contacts. Please make sure that all contacts are entered properly. ")
            End If
            Call CenterForm(Me)
            Me.Focus()
        End If
    End Sub


Answer this question

Form Activated Event Going in multiple loops

  • Vitaly Demin

    It appears that the Activated event is just firing in ways you hadn't expected when writing the code. Is it possible that you could put this code in another event handler  That is, why must it be in the Activate event  I shy away from using Activated for this very reason.
  • Form Activated Event Going in multiple loops