0

I have an Access application that uses menus and pop-up forms. I have a button on the main dashboard form that begins an MS Outlook function that processes emails in an Outlook Folder. This process takes quite a while depending on how many messages are in that folder. I want to give the user status of the progress being made but the form isn't actually being displayed on screen until the process is complete. A Dashboard button opens the display (DoCmd.OpenForm "frmProcessMail", acNormal) and the process code is launched from the form load event but nothing shows up on the screen until the VBA code exits. I've looked everywhere for a way to make this work and all I've come up with is adding another button to the form being launched that actually calls the mail routine so I'll have a visible control to give the user status updates through. Is there a better way? I'd rather not force the user to press additional buttons to get the process started. The OnOpen and OnLoad events fire before the form is displayed. The After Render, After Final Render, and After Layout events don't fire at all. Next I'll try putting a timer on the form to push the button for the user after some delay. It seems like a terible hack but if it gets-er-dun... so be it.

UPDATE: I added a 2 second timer that reset it's interval to 0 and called the button click event and I hid the button. It works, I can display and update the progress bar and activity fields. I still think the "After Render" event should fire when the form becomes visible on the screen; it would make for a cleaner implementation.

SOLVED:
I searched some more and came across this Related Question in which @Tom Robinson responded with Me.Visible = true. That's all it takes. I tested this with several message boxes in a few form events. Normally the Open Event and then the Load event and the Current event are all processed before Access will display the actual form. Placing the Me.Visible or alternatively the SetFocus directive tells Access to render the form on the screen. (I came across the SetFocus directive in another post but I've lost the link.)

Note: I got some different responces with different versions of Access. Perhaps it was related to where the 'visible' request was placed. At one point the "Activate" and "GotFocus" events fired before the "Load" event of a subform when I put the visible request in the Open event.

Andre - I tried shorter time periods for the timer solution but even though I set the timer period to 0 as the first instruction in the called routine the system stacked several loops on top of one another before the process completed. It seemed that the timer setting change wasn't applied until the event completed.

  • Could the button which opens frmProcessMail also call the long-running procedure after it opens the form? – HansUp Oct 13 '22 at 18:20
  • Yes, it's either this ^ or the Timer event. Note that you don't need 2 seconds, 1 ms is enough. – Andre Oct 13 '22 at 19:09
  • a couple of old suggestions from: https://www.access-programmers.co.uk/forums/threads/run-code-in-background.223446/ – mazoula Oct 15 '22 at 04:35

0 Answers0