Label on form will not Update as the code runs in the background

CarlRostron

Registered User.
Local time
Today, 23:55
Joined
Nov 14, 2011
Messages
88
I have a userform that pops up when I am implementing a VBA subroutine. The nature of the form is simply to update the user what progress through the operation the code is using a label called lblProgressText.

So, I have a form called frmProgress and in my loop I use:

Code:
    DoEvents
    Form_frmProgress.lblProgressText.Caption = Format(rsLongItems.PercentPosition / 100, "0.00%") & " - Long items"
    Form_frmProgress.pbProgressBar = rsLongItems.PercentPosition
    Form_frmProgress.Requery
    Form_frmProgress.Refresh
    Form_frmProgress.Repaint

I know I don't need the .requery, .repaint and .refresh lines but I put in there just to check it wasn't that causing the issue.

When my code runs, the form is opened using:
Code:
  Form_frmProgress.Modal = False
  DoCmd.OpenForm Form_frmProgress.Name, acNormal, , , , acWindowNormal

The form Popup property is set to Yes.

The lblProgressText control just wont update (but earlier today it was so maybe I have broken something).

Btw, all this code is run from a Module, not in the form object.

has anyone got any ideas or pointers which I can check as to why this control caption will not update itself?

Thanks
 
You have ventured into a minefield using your Form_frmName ... syntax for referring to items on a form. Unless you know excactly what you are doing DON'T! Because it causes instances of the form to open in the background - invisibly - and can provide untold debugging fun for weeks!

The proper syntax is

Forms!myForm!myControl or Forms!myForm.myFormProperty
 
Fabulous, you advice was bang on. Thanks for your help. Resolved.
 
also you might find screen repaints just don't happen until data changes, so you might find this order achieves what you want

Code:
Form_frmProgress.lblProgressText.Caption = Format(rsLongItems.PercentPosition / 100, "0.00%") & " - Long items"
Form_frmProgress.pbProgressBar = rsLongItems.PercentPosition
DoEvents
 

Users who are viewing this thread

Back
Top Bottom