Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening forms in Dialogue mode (Access 97 Win2k)

    Hello again....

    After reading the post 'requery' I have been wondering if all VBA modules will stop running once a form is opened by them in dialogue mode? (or is it only the ones called from the 'not in list' event?)

    If this is true, would it be possible to 'complete' the required operation by having 'the rest' of the module run from the 'on open' event of the form called?

    Thanks

    Ian

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    It's the calling code that will pause execution until the Form is hidden or closed.

    If there is any code in the dialog form, that will still run, but the procedure that called the form will pause.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    You can't say that "all VBA modules will stop running". A procedure (a sub or function) can run; a module doesn't "run".

    If you have a procedure, for instance the OnClick event procedure of a command button on a form that opens another form using
    DoCmd.OpenForm "FormName"
    the procedure will continue with the next instruction after DoCmd.OpenForm. If the form is opened with
    DoCmd.OpenForm "FormName", , , , , acDialog
    the procedure will wait until the form "FormName" has been closed by the user before continuing. This holds for any kind of code that opens a form.

    If you want the code to run on, don't use the acDialog parameter. If you want to prevent the user from activating other forms from "FormName", set the Modal property of "FormName" to Yes.

    Note: if you open a form from a NotInList event procedure of a combo box, with the purpose of letting the user enter data for a new item to be added to the row source of the combo box, you will run into problems if you don't use acDialog: the NotInList procedure will run on and set Response = acDataErrAdded before the new item has actually been added. This will probably cause the default error message to be popped up.

  4. #4
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    OK, that's pretty much what I thought was the situation, it doesn't matter how a module is started, it will pause once a form is opened in dialogue mode. This did cause me a problem when I set the 'setwarnings' method and then tried to open the resulting form in design mode.... The screen appeared to have locked. I now know that what I thought was happening was the case.

    Thanks

    Ian

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Edmonton, Alberta, Canada
    Posts
    326
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    Very minor nitpicky correction. The code that called the dialog form will continue after the dialog form is closed or made invisible. Making the form invisible lets subsequent code retrieve the values from the controls on the form; handy for making fancy dialog boxes.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    Thanks, Douglas. That's not nitpicking, it's a very useful addition for other Loungers reading this. I often use the technique of having the OK button hide a dialog form, so that the calling form can get at the values of the controls of the dialog. Just don't forget to close the hidden dialog form when you're done with it; otherwise it will come up next time with old values still filled in.

  7. #7
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening forms in Dialogue mode (Access 97 Win2k)

    Just to throw my two cents in:

    It's been explained about modal forms already in this thread. However, just to bring in another aspect, all code works this way, whether it is on a form or not. When a function or sub, calls another function or sub, the calling function/sub pauses until the new function or sub hits and End Function/Sub, or Exit Function/sub. That is part of 'single threading'. Your application runs in one thread, so your code follows a simple step by step procedure. Now, you can have multiple forms running seperate functions, but in reality, your code is only doing one line at a time, in fact it does one function/sub at a time, unless you use DoEvents, which frees the thread up to run code that is waiting.

    Access forms are Class modules. If you have ever made your own class modules, you'd know that a Class module has an Initialize event. If you put a loop in that event, the calling function/sub waits until the class is completely initialized. You could create a 'modal' class, by putting:

    Do while boolStopLoop=False
    DoEvents
    Loop

    Have the boolStopLoop variable as a global, or Class based variable. If that is in your Initialize code, you class will work, and keep it's calling code 'paused'. When you close your class (there is a terminate event), you simply set the boolean variable to True, stopping the loop, and allowing your calling code to continue.

    I personally have never done this, so I could be wrong on whether it works or not. What's more important is the concept of how your code works.

    Drew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •