Progress display doesn't work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    Progress display doesn't work

    Okay, I bet this is something simple ... I'm running through a pair of loops and I want to show my progress as I go. The outer loop advances through the customer table, the inner loop advances through product classes. Each time I advance to a new customer, I set me!lblCustomer. Caption to be the customer ID, and each time I advance a product class I set me!lblClass.Cap tion to equal the product class. The trouble is, nothing shows in these captions until the very end, after I have displayed my "Done" message. However, if I use the debugger and stop in the loops, the captions display as they should.

    I'd appreciate any comments or suggestions.
    Jim

    Here's my code. It doesn't matter whether grpActionType = 1, 2, or 3, it behaves the same way.
    Code:
        DoCmd.Hourglass False
        Me!lblCustomer.Visible = True
        Me!lblClass.Visible = True
        
        rstCustomers.MoveFirst
        Do While Not rstCustomers.EOF
            Me!lblCustomer.Caption = rstCustomers!strCustomerID
            If Me!grpActionType = 1 Then ' deleting
                rstProductClass.MoveFirst
                Do While Not rstProductClass.EOF
                    strCriteria = "strCustomerID = """ & rstCustomers!strCustomerID & """ and strItemClass =""" & rstProductClass!strStringItem & """"
                    Me!lblClass.Caption = rstProductClass!strStringItem
                    Me!txtProgress = rstCustomers!strCustomerID & " " & rstProductClass!strStringItem
                   ' Me.Refresh
                    
                    rstSpecialPricing.FindFirst (strCriteria)
                    If Not rstSpecialPricing.NoMatch Then
                        rstSpecialPricing.Edit
                            rstSpecialPricing("ynRestricted") = False
                        rstSpecialPricing.Update
                    End If
                 rstProductClass.MoveNext
                 Loop
            
            ElseIf Me!grpActionType = 2 Then 'copy
                
                rstProductClass.MoveFirst
                Do While Not rstProductClass.EOF
    '                strCriteria = "strCustomerID = """ & Me!cboFromAccount & """ AND strItemClass =""" & rstProductClass!strStringItem & """"
                    strCriteria = "strCustomerID = """ & Me!cboFromAccount & """"
                    Me!lblClass.Caption = rstProductClass!strStringItem
                    Me!txtProgress = rstCustomers!strCustomerID & " " & rstProductClass!strStringItem
                    'Me.Refresh
                    rstSpecialPricing.FindFirst (strCriteria)
                    
                    If Not rstSpecialPricing.NoMatch Then
                        Dim ysnRestricted As Boolean
                        ysnRestricted = rstSpecialPricing!ynRestricted
                        
                        strCriteria = "strCustomerID = """ & rstCustomers!strCustomerID & """ AND strItemClass =""" & rstProductClass!strStringItem & """"
                        rstSpecialPricing.FindFirst (strCriteria)
                        If Not rstSpecialPricing.NoMatch Then
                            rstSpecialPricing.Edit
                                rstSpecialPricing("ynRestricted") = ysnRestricted
                            rstSpecialPricing.Update
                        Else
                            rstSpecialPricing.AddNew
                                rstSpecialPricing("strCustomerID") = rstCustomers!strCustomerID
                                rstSpecialPricing("strItemClass") = rstProductClass!strStringItem
                                rstSpecialPricing("dtmBeginDate") = #1/1/2000#
                                rstSpecialPricing("dtmEndDate") = #12/31/2099#
                                rstSpecialPricing("ynRestricted") = ysnRestricted
                            rstSpecialPricing.Update
                        End If
                    End If
                 rstProductClass.MoveNext
                 Loop
            
            ElseIf Me!grpActionType = 3 Then  ' new restrictions
                rstProductClass.MoveFirst
                Do While Not rstProductClass.EOF
                    strCriteria = "strCustomerID = """ & rstCustomers!strCustomerID & """ & strItemClass =""" & rstProductClass!strStringItem & """"
                    Me!lblClass.Caption = rstProductClass!strStringItem
                    Me!txtProgress = rstCustomers!strCustomerID & " " & rstProductClass!strStringItem
                    'Me.Refresh
                    rstSpecialPricing.FindFirst (strCriteria)
                    If Not rstSpecialPricing.NoMatch Then
                        rstSpecialPricing.Edit
                            rstSpecialPricing("ynRestricted") = True
                        rstSpecialPricing.Update
                    Else
                            rstSpecialPricing.AddNew
                                rstSpecialPricing("strCustomerID") = rstCustomers!strCustomerID
                                rstSpecialPricing("strItemClass") = rstProductClass!strStringItem
                                rstSpecialPricing("dtmBeginDate") = #1/1/2000#
                                rstSpecialPricing("dtmEndDate") = #12/31/2099#
                                rstSpecialPricing("ynRestricted") = True
                            rstSpecialPricing.Update
                    End If
                 rstProductClass.MoveNext
                 Loop
            End If
        rstCustomers.MoveNext
        Loop
        
        rstCustomers.Close
        rstSpecialPricing.Close
        rstProductClass.Close
        Set rstCustomers = Nothing
        Set rstSpecialPricing = Nothing
        Set rstproductionclass = Nothing
        Set dbs = Nothing
        
        vbresult = MsgBox("Done", vbOKOnly)
        
        DoCmd.Hourglass False
        Me!lblCustomer.Visible = False
        Me!lblClass.Visible = False
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. Access takes a relatively lazy approach to screen refresh, so when you change your caption within the loop you should use me.repaint to force a screen refresh (not me.refresh - commented out in line 14, 33 etc).

    There are 98 lines listed in your code, of which only a small number are really relevant to your problem. It would certainly help us to read your post more easily if you could simply excerpt the relevant lines instead of posting it all, interesting though it is!

    -Stewart

    Comment

    • Scott Price
      Recognized Expert Top Contributor
      • Jul 2007
      • 1384

      #3
      Try using Me.Repaint instead of the Me.Refresh (that you have commented out). Here is the MS Help file on Repaint:

      Originally posted by MS Help File
      Repaint Method
      See AlsoApplies ToExampleSpecif icsThe Repaint method completes any pending screen updates for a specified form. When performed on a form, the Repaint method also completes any pending recalculations of the form's controls.

      expression.Repa int
      expression Required. An expression that returns one of the objects in the Applies To list.

      Remarks
      Microsoft Access sometimes waits to complete pending screen updates until it finishes other tasks. With the Repaint method, you can force immediate repainting of the controls on the specified form. You can use the Repaint method:

      When you change values in a number of fields. Unless you force a repaint, Microsoft Access might not display the changes immediately, especially if other fields, such as those in an expression in a calculated control, depend on values in the changed fields.


      When you want to make sure that a form displays data in all of its fields. For example, fields containing OLE objects often don't display their data immediately after you open a form.
      This method doesn't cause a requery of the database, nor does it show new or changed records in the form's underlying record source. You can use the Requery method to requery the source of data for the form or one of its controls.

      Notes

      Don't confuse the Repaint method with the Refresh method, or with the Refresh command on the Records menu. The Refresh method and Refresh command show changes you or other users have made to the underlying record source for any of the currently displayed records in forms and datasheets. The Repaint method simply updates the screen when repainting has been delayed while Microsoft Access completes other tasks.


      The Repaint method differs from the Echo method in that the Repaint method forces a single immediate repaint, while the Echo method turns repainting on or off.
      Example
      The following example uses the Repaint method to repaint a form when the form receives the focus:

      Private Sub Form_Activate()
      Me.Repaint
      End Sub

      Regards,
      Scott

      Comment

      • Scott Price
        Recognized Expert Top Contributor
        • Jul 2007
        • 1384

        #4
        Beat me to it, Stewart! Good on you :-)

        Regards,
        Scott

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          And , of course, it may simply be that the loop is executing too quickly for the human eye to register the changes in the label caption!

          Linq ;0)>

          Comment

          • jimatqsi
            Moderator Top Contributor
            • Oct 2006
            • 1293

            #6
            Thanks very much to all who replied, me.repaint did the trick. :)

            Comment

            • Scott Price
              Recognized Expert Top Contributor
              • Jul 2007
              • 1384

              #7
              You're quite welcome! Glad to be able to help.

              Regards,
              Scott

              Comment

              Working...