Results 1 to 6 of 6

Thread: [RESOLVED] Design Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Cambridge UK
    Posts
    22

    Resolved [RESOLVED] Design Question

    Hi

    I have a design issue which I'm unsure how best to resolve and would really appreciate any help.

    My app has a main form (it's the startup form). It includes a number of menu items which typically open modal sub forms. However there are 2 menu items which just need to open an Outlook Explorer calendar for the user to manipulate appointments.

    My VB6 version used hidden sub forms to do this and handle the subsequent interaction between the user and the Outlook objects in the Calendar. I need to stop the user interacting with the main form while the Outlook Explorer is open, ie as if the Explorer window were a modal sub-form to the main form. So I manually disable the main form while the Outlook activity is going on, then (try to) enable it when the user closes the Outlook Explorer window. Problem is I can't seem to get a reference to the main form from the sub form to do this, nor pick up an event in the main form which I could use to trigger the enabling of the main form.

    An alternative might be to delete the hidden sub forms & put all the code in the main form, but this would be quite ugly; I think I would need to maintain two parallel sets of Outlook objects at the top level in the main form for each of the two functions (a number of the Outlook objects are declared With Events). I would have to have for example mobjOutlookExplorerFunction1 and mobjOutlookExplorerFunction2.

    So - I'm wondering what is the neat elegant solution to this that must be out there?

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Design Question

    When you create a form, you must be doing something like this:

    Code:
    Dim Thing As New SubFormThatDoesOutlookStuff
    Thing.GoDoOutlookStuff
    You can just pass in a reference for the main form, just make sure you have a method to re-enable it!:

    Code:
    Dim Thing As New SubFormThatDoesOutlookStuff
    Thing.GoDoOutlookStuff(Me)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Cambridge UK
    Posts
    22

    Re: Design Question

    Thanks for responding! This does sound blindingly obvious when you put it like that :-) however when I try what I think you are saying it doesn't work.

    I am starting the sub form from the main form like this:

    Code:
    Dim frmModAssessAppt As New frmModAssessAppt
    frmModAssessAppt.Start(Me)
    Have added a sub to the main form to do the enabling:

    Code:
    Public Sub enableMe()
        Me.Enabled = True
    End Sub
    The modified sub form:

    Code:
    Private mMainForm As New frmMain
    
    Public Sub Start(ByRef MainForm As frmMain)
       mMainForm = MainForm 
       ...outlook code
    End Sub
    
    Private Sub myExplorer_Close() Handles myExplorer.Close
       ... tidy up outlook objects
       mMainForm.enableMe() 
       Me.Close()
    End Sub
    The enableMe sub gets called and the Me.Enabled = True line is executed, but the execution seems to stop there, and the Main Form while no longer greyed out is not responding to keyboard or mouse... Any idea what I have wrong? Thank you for your patience!

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Design Question

    Private mMainForm As New frmMain

    You do realise this creates a second copy of the main form? Also, you do not need to pass the argument ByRef.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Cambridge UK
    Posts
    22

    Re: Design Question

    Yes OK I now have
    Code:
    Private mMainForm As frmMain
    , but same result, the main form is not greyed out but does not respond to keyboard or mouse. Grrrr.

    Think this is something to do with the Outlook integration, because if I comment out the code which instantiates the Outlook objects, displays the Explorer and tidies up at the end, ie I just go straight from my sub form Start function to an Explorer_Close() function which just enables the main form, it works fine.

    Feels a bit like a problem I had before with stuff running on different threads which I resolved by testing for InvokeRequired...?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Cambridge UK
    Posts
    22

    Re: Design Question

    Yep fixed it, it needed an InvokeRequired check in the enableMe function in the Main Form.

    Thanks for your support Grimfort

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