Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Figure out what the active form is

Status
Not open for further replies.

YanaD

Programmer
Mar 22, 2001
38
0
0
US
I need to get a name of active form. Ex: I have 3 forms
frmA, frmB, frmC. On both forms frmA and frmB I have a control txtText with some data. Let say first I have frmA open and when i click on command buttom, I need frmC to open and on load event i need to check what was the active form before frmA or frmB + what was in the txtText.
If something is unclear, let me know, but basically I need a full syntax with a declaration statment and set statment of openning the active form.
 
Hello

How about a form level property to hold the initialising form

i.e.
in the form global declaration put
Dim m_frmCallingForm as form

Public Property Let sFromForm(ByVal v_frmCallForm As form)

m_frmCallingForm = v_frmCallForm

End Property

Now before you show the form you can do i.e. on the command button;
frmC.sFromForm = me
frmC.show

And when frmC is shown is has a reference to the calling form

(You could modify this to contain the text box only)
 
I hope I haven't completely misunderstood you, but here goes. I would have form1 or form2 put it's name into the Tag property of form3. (ex Form3.Tag= "Form1")You can also put the value of Text1 in here, separating the values with a ~ or something. Then, when you want to return, have it cycle through the forms within the procedure, and find the one with a name that matches the value of form3's Tag. Hope I didn't completely miss the mark on what you were asking for there.
 
Change perspective: The problem is not telling the form who called it. It's allowing the form to identify who loaded it.

A global variable is needed, the scope needs to include the forms that wish to pass this information so application global is essential.

Create a concept, let's call it registering. In this process the form identifies itself as the currently active form.

Since we created this process as an application standard, we know that when a form registers, the registration variable has the form that activated it.

IAW:
Instead of having to tell each form who you are before you invoke them you can simply register yourself in your load/activate method. If you need to know who activated you, check before you register.

---

If you want to really have fun. Create a MRU list and use that instead of a simple variable. You could also have the unload event remove its name from the list.

I recommend a MRU instead of a stack, forms do not follow a rigid enough rule to make the stack based solution stack work.


Finally, making registration a load related event, you might run into problems when forms hide and show instead of unload and load. Activates suits the property much better.

Wil Mead
wmead@optonline.net

 
A global variable is possible but anti-object oriented because it violates the encapsulation (information hiding) requirement of OO. The form classes are no longer defined just by their Public properties and Methods. An external global variable which must be defined in a BAS module does not qualify as an interface. In the "old days", this was called a "pathological" binding of modules. Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top