Simultaneous Code Execution?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dgunner71
    New Member
    • Jun 2010
    • 110

    Simultaneous Code Execution?

    I have a form (Form A) that has a print command button - the resulting report takes about 3 to 5 seconds to open.

    To notify the user, I developed a form (Form B) and code to animate a "Your Report is Being Generated" display (there are 4 dots that move across the form.) This is the only purpose of this Form B - it is closed when the calling procedure (located on Form A) completes.

    The code on Form B works perfectly when I open the form on it's own (all animation is perfect) however, when the form is opened from Form A, everything works fine however, Form B is not animated (it is just a static image.)

    Simplified code example is below:
    Code:
        ‘Hides Form A (Calling Form)
        Me.Visible = False 
    
       ‘Opens Form B (“Your Report is Being Generated” Form with Animation)
        DoCmd.OpenForm "FormB"
        
        DoEvents
    
        DoCmd.OpenReport "rptSaleOrderPrintOut_Portrait", acViewReport
                 With Reports!rptSaleOrderPrintOut_Portrait.Report
                    .Filter = Nz(Me.sfrmSaleOrderSearch.Form.Filter, "*")
                    .FilterOn = IIf(Nz(Me.sfrmSaleOrderSearch.Form.Filter, "") = "", False, True)
                 End With
    
       DoCmd.Close acForm, "FormB"
    I excluded the code Form B (all located in the Form Time event) as it seems to work well but I can share this if needed as well.

    Thanks in advance for any assistance.

    Gunner
    [IMGNOTHUMB]https://bytes.com/attachments/attachment/9303d1514835264/form-logo-removed-.jpg[/IMGNOTHUMB][IMGNOTHUMB]https://bytes.com/attachments/attachment/9304d1514835264/form-b-logo-removed-.png[/IMGNOTHUMB]
    Attached Files
    Last edited by NeoPa; Jan 3 '18, 05:52 PM. Reason: Space missing, clarification.
  • dgunner71
    New Member
    • Jun 2010
    • 110

    #2
    I also noted that if I do not close the Form B, the animation begins working on its own as soon as the report opens. Not sure if that helps...

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3662

      #3
      dgunner71,

      Unfortunately, as far as I know, MS Access can only do "one thing at a time". As soon at you open Form B, although you use the command DoEvents to initiate the actions, as soon as you execute code to open the Report, all activity on Form B will pause until the processes complete for that Report. This is also why once the Report is open, Form B begins to function "normally".

      This is not a "solution" to your question, but rather an explanation about why you are getting those particular results.

      Hope this hepps!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        TwinnyFo's spot on. I can only wonder why you'd imagine the code could control Form B when the report is being opened. There is no possibility of executing DoEvents from within the processing of the data.

        There is some small scope to be had from events which fire during the formatting of each section so you could try a DoEvents in there. It's likely to be a small fraction of the overall time though. Usually, when a report is being prepared and the initial grabbing of the data takes more than a second or two, you'll see a progress indicator in the status bar anyway. Until that's completed I'd not expect your form to have any activity. In most cases the time to format and show the data once grabbed is minimal anyway. A second or so even for a long report.

        As I say, you may like to try that but I don't expect it to give you much joy. VBA is fundamentally a single process, allowing only one thing to run at any one time and when data is being grabbed then that process is busy.

        Comment

        • dgunner71
          New Member
          • Jun 2010
          • 110

          #5
          Thanks all - this answers my question.

          Happy New Year.

          Gunner

          Comment

          Working...