Function PrevInstance() As Boolean If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then PrevInstance = True Else UserName = Environ("UserName") Computername = Environ("COMPUTERNAME") PrevInstance = False End If Dim i, n As Integer, RepForm As String For i = My.Application.OpenForms.Count - 1 To 1 Step -1 RepForm = My.Application.OpenForms.Item(i).Name For n = My.Application.OpenForms.Count - 1 To 1 Step -1 If My.Application.OpenForms.Item(n).Name = My.Application.OpenForms.Item(i).Name And n > i Then My.Application.OpenForms(i).Close() PrevInstance = True Exit Function End If Next n Next i End Function
source share