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 ?
kycheangAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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
frmCustomer.Zorder
frmCustomer.Show

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!
0
 
mcriderCommented:
Try this:

   If formx.visible=true then
       'ALREADY LOADED AND VISIBLE
   else
       'NOT VISIBLE, SHOW IT
   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...


Cheers!
0
 
marcj1Commented:
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
        Else
            '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
0
All Courses

From novice to tech pro — start learning today.