Results 1 to 8 of 8

Thread: Identify the Calling Form

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Identify the Calling Form

    hello guys,

    suppose i have got 3 forms in my project A, B and C. Both A and B forms can call the C Form. Now when C form is loaded i want to know which form has called the C form. is it possible to pass or receive any arguement (like functins and procudures) at the Form_Load and Form_Unload event?

    pls guide me.

    regards,
    prakash

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    You can do this by creating a Module and defining a global variable in it. You will then set this global variable to a value of your choice before calling the 'C' form. Use one value for a call from the 'A' form, and another for the 'B' form. The Form_Load section of the 'C' form can then test this variable to see which form called it.

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    there are many many ways to achieve this. eg using a Public variable as suggested by jdc and that is normally the method i use but u can also use the form's tag property. eg
    VB Code:
    1. 'ON FORM 1
    2. Private Sub Command1_Click()
    3.     Form3.Tag = Me.Name
    4.     Form3.Show
    5. End Sub
    6.  
    7. 'ON FORM 2
    8. Private Sub Command1_Click()
    9.     Form3.Tag = Me.Name
    10.     Form3.Show
    11. End Sub
    12.  
    13. 'ON FORM 3
    14. Private Sub Form_Activate()
    15.     MsgBox Me.Tag & " called me"
    16. End Sub
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    i was expecting such answers. but i don't want to use global variables. when my form c is called i want to manipulate some variables of the calling form.

    for eg. if form A has called form C then FormA.var1 = xyz
    if form B as called form C then FormB.var2 = abc.

    BTW what does this "Tag" property stands for

    pls guide

    prakash

  5. #5
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    The tag hold any extra data which your form could possibly use for these kinds of abstract things.

  6. #6
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi again
    I dont quite understand what u mean by manipulating variables on the calling form.... sounds a bit spaghetti code but anyhow u can access the variables and controls like this...
    VB Code:
    1. 'ON FORM 1
    2. Public MyFormVar As String
    3.  
    4. Private Sub Command1_Click()
    5.     Form3.Tag = Me.Name
    6.     Form3.Show
    7. End Sub
    8.  
    9. 'ON FORM 2
    10. Public MyFormVar As String
    11.  
    12. Private Sub Command1_Click()
    13.     Form3.Tag = Me.Name
    14.     Form3.Show
    15. End Sub
    16.  
    17. 'ON FORM 3
    18. Private Sub Form_Activate()
    19.     Dim lfrm As Form
    20.     DoEvents
    21.     For Each lfrm In Forms
    22.         If lfrm.Name = Me.Tag Then
    23.             lfrm.MyFormVar = "U changed me"
    24.             lfrm.Text1.Text = lfrm.MyFormVar
    25.             Exit For
    26.         End If
    27.     Next
    28. End Sub
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  7. #7
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    Digitalerror is a crackhead

  8. #8
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    On form C, you have a Sub which manipulates the variables on the calling form I assume.

    So on Form A & B, call this sub, and add an extra parameter.

    FORM A / B

    Sub
    FormC.Show
    FormC.ChangeVariables(Me)
    End Sub


    FORM C

    Sub ChangeVariables(FormName as Form)
    FormName.x = 1
    FormName.y = 2
    End Sub



    That do?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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