Results 1 to 6 of 6

Thread: Help Routing Between Forms

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Question Help Routing Between Forms

    I have a form named 'FrmCustomers' which contains a list box containing customers names, allowing the user to choose a customer to view ,edit etc.
    This form may be loaded from a number of different forms within the app
    i.e. assuming the app is in main form 'FrmMain' - to load customer form I use the following code:

    Private sub CmdLoadCust_Click
    Origin=Me.Name 'This is used to determine the original form
    Me.Enabled=False
    FrmCustomers.Show
    End Sub

    Now to return to the original form I put the following code in the form Unload event of the form 'FrmCustomers' :

    Private Sub Form_Unload(Cancel As Integer)

    if Origin="FrmMain" then FrmMain.Enabled=True
    If Origin="Frm1"then Frm1.Enabled=True
    If Origin="Frm3" then Frm3.Enabled=True

    End Sub

    etc. etc. etc.

    My question is :

    Is there not an easier way to return to the form which loaded FrmCustomers in the first place ?

    Pse Help!!!

    Ken

  2. #2
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Help Routing Between Forms

    You could use a function to do it. Then pass the form as an argument. Something like this might work but I havn't tested it:

    VB Code:
    1. ' in a module
    2. Public g_Caller As Form
    3. Public Function ShowCustomers(Caller As Form)
    4.     g_Caller = Caller
    5.     Caller.Enabled = False
    6.     FrmCustomers.Show
    7. End Function
    8.  
    9. Public Function HideCustomers()
    10.     FrmCustomers.Hide
    11.     g_Caller.Enabled = True
    12. End Function

    You should probably add some error checking in there though.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Help Routing Between Forms

    It looks like frmCustomers is meant to be a Modal form. Showing a Modal form is similar to a message box, the user must complete the task offered by the Form before doing anything else. If that is the case then simply use

    VB Code:
    1. Private sub CmdLoadCust_Click
    2.    FrmCustomers.Show vbModal, Me ' the second argument is optional.
    3. End Sub

    When frmCustomers is Unloaded or Hidden, code execution returns back to the calling form.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: Help Routing Between Forms

    Thanks Guys

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: Help Routing Between Forms

    Ps brucevde thanks this is exactly what I was looking for !

  6. #6
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Help Routing Between Forms

    Good one brucevde. I didn't know about that.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

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