Results 1 to 4 of 4

Thread: Detecting if a vbModal form is open

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    62
    i have a timer event in my app that checks a condition, if the condition is true then i popup a display form, however; i get an error if a modal form is already open. i have good error code in my app. the very first line is similiar to this.
    On Error GoTo Timer1_Timer_Err

    but on my timer event condition true i have to do something like this to keep from getting an error.
    On Error Resume Next
    frmCalendarReminder.Show
    On Error GoTo Timer1_Timer_Err

    is there a way to detect an open modal form, then i can just wrap the form.show around and if statement. thanks...

    jj

  2. #2
    Guest
    This code will determine if a form is already open.

    Code:
    Tip by Sam Huggill
    
    
    Public Function FormLoadedByName(FormName As String) As Boolean  
    Dim i As Integer, fnamelc As String  
    fnamelc = LCase$(FormName)
    FormLoadedByName = False
    For i = 0 To Forms.Count - 1 
    If LCase$(Forms(i).Name) = fnamelc Then      
    FormLoadedByName = True
    Exit Function
    End If
    Next
    End Function
    
    Private Sub Command1_Click()
    If FormLoadedByName("Form2") = True Then
    MsgBox "Form2 is loaded"
    Else
    MsgBox "Form2 is not loaded"
    End If
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    62
    That would work, however; my project has many modal forms so i have have to do a dectect on each of them. Does anyone have any comments on this option. I know the error number that is raised if I try to show a form and a modal form is already open, so i could continue to use the On Error Resume Next, then put an if after the form.show line that says if err.number <> 420 (420 is the error raised in this case) then goto my error handling code. I don't like to use On Error Resume Next, but as of now I don't have any other options.

    jj

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Why don't you use a global variable to track the status of open, modal forms? You would just set the variable to true when a modal form is opened, and set it back to false when that form closes. You then just check the variable before attempting to open another modal form.
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width