How to check active form

Before i show or activate the current form, I want to determine whether the customer form already show on screen, If yes I will retrieve the customer # else I set the customer # to blank. My problem is how can I check whether the customer form is show or active ?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

tirupur_selvaConnect With a Mentor Commented:
DONOT create an instance of the form customer like(Dim frmCust as New frmCustomer). Just directly load the form. Thats it. For example, consider the following:

 Form Customer's name is 'frmCustomer'

In the appropriate event paste the following code:

Load frmCustomer

With the above code, if the form is loaded for the first time, its normal. If its not loaded the first time (ie)if the menu is clicked when the form is already loaded, the form will be brought to the front with the previously entered details.

Hope you get it right and hope this is what you were looking for!
Try this:

   If formx.visible=true then
   end if

Be careful... If you have any statements in the form_load event and the form has not been loaded, the event will fire after the form.visible propery is checked...

Otherwise, you can create a public or global variable for each form as BOOLEAN... then set the variable to TRUE when you show the form and FALSE when you hide it... You can then test it anytime...

Substitute the name of your customer form for sFormName.  This suggestion gets around the limitation of the form not being loaded.

Happy hunting!

Dim n As Long
Dim sFormName As String
Dim bFormIsLoaded As Boolean

sFormName = "Form1"

For n = 0 To Forms.Count - 1
    If Forms(n).Name = sFormName Then
        If (Forms(n).Visible) Then
            'form is loaded and visible
            'form is loaded and NOT visible
        End If
        bFormIsLoaded = True
    Else    'do nothing--this is not the form of interest
    End If
Next n

If (Not (bFormIsLoaded)) Then
    'form is NOT loaded
Else: End If
All Courses

From novice to tech pro — start learning today.