• Opening forms in Dialogue mode (Access 97 Win2k)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Opening forms in Dialogue mode (Access 97 Win2k)

    Author
    Topic
    #380573

    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

    Viewing 2 reply threads
    Author
    Replies
    • #637818

      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.

    • #637825

      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.

      • #637833

        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

      • #637878

        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.

        • #637883

          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.

    • #637964

      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

    Viewing 2 reply threads
    Reply To: Opening forms in Dialogue mode (Access 97 Win2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: