-1

I am creating a project in which there is a loop of 3 forms form1->form2->form3->form1->form2->form3.... and loop stays until application is exit. Loop is made through a button. In form3 I have used interop.excel and copied data from a worksheet to an array which is done by selecting an name of excel file from the listbox.

Now the problem is that every time I go from form3 to form1 form3 looses focus and form2 always create a new instance of form3. So even my previous form3 is open it opens new form3.

I have seen and tried solution given on How can I loop through all the open instances of a particular form? and Application.OpenForms.Count = 0 always but it didn't help.

Is there a way that form2 can check if there is any instance of form3 or not and then take a decision to make new instance of form3 or give focus to previous form3 .

Please help me. Thank you in advance.

Community
  • 1
  • 1
Sondhi
  • 1
  • 3

1 Answers1

0

From This Thread

Function IsUserFormLoaded(ByVal UFName As String) As Boolean 
Dim UForm As Object 

IsUserFormLoaded = False 
For Each UForm In VBA.UserForms 
    If UForm.Name = UFName Then 
        IsUserFormLoaded = True 
        Exit For 
    End If 
Next 
End Function 'IsUserFormLoaded

so for your needs you could do

If IsUserFormLoaded(UserForm3) Then
    'Code if it is open here
Else 
    'Code if it is NOT open here
End If
user2140261
  • 7,855
  • 7
  • 32
  • 45