Results 1 to 8 of 8
  1. #1
    atzdgreat is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    27

    Label as Status and Percentage inside listview loop not working using form_timer

    hi im just wondering why my label doesnt work inside the listview loop. only the progressbar do.



    Code:
    Private Sub Form_Load()
        Dim ProgBar  As MSComctlLib.ProgressBar
        Me.lblPerc.Caption = "0%"
        Me.lblSaveCaption.Caption = "Preparing Datas"
        
        Set ProgBar = Me.progBar1.Object
        ProgBar.BorderStyle = ccNone
        ProgBar.Appearance = ccFlat
        ProgBar.Min = 0
        ProgBar.Value = 0
        Set ProgBar = Nothing
        
        Me.TimerInterval = 1
    End Sub
    
    
    Private Sub Form_Timer()
        Call SaveStaffAttendance
    End Sub
    
    Private Sub SaveStaffAttendance()
        Dim LV  As MSComctlLib.ListView
        Dim NewProgBar As MSComctlLib.ProgressBar
    
        Set LV = Form_StaffTimeAttendance.ListView2.Object
        NewProgBar.Max = LV.ListItems.Count
        For i = 1 To LV.ListItems.Count
            Me.lblSaveCaption.Caption = "Updating Staff [" & LV.ListItems(i).Text & "] " & LV.ListItems(i).SubItems(1)
            NewProgBar.Value = NewProgBar.Value + 1
            Me.lblPerc.Caption = Format(NewProgBar.Value / NewProgBar.Max * 100, "##0") & "%"
        next i
        Me.TimerInterval = 0
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    probably because you have the form timer set at 1 millisecond. If 1 second is what you want, the value should be 1000.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    atzdgreat is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    27
    thanks for your reply. i've tried changing timer but still it wont change the percentage.Click image for larger version. 

Name:	Test.JPG 
Views:	23 
Size:	18.2 KB 
ID:	39895

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I figured a caption not being calculated 1000 times per second was a good place to start. I think there are still 2 possibilities; the form needs repainting or the expression does not evaluate to anything
    1) try Me.Repaint before Next i and if not, Me.Recalc
    2) step through your code and check the returned value of the expression. Note that in order to process the expression, you will have to step on to Next i. If you stop on the expression line, the calculation will not have been processed so it can cause you to think that it's not working. If when you do this the expression returns an empty string ("") then that is why you don't see the calculation in the label.

  5. #5
    atzdgreat is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    27
    thank you so much. it works

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Just to wrap thing up, how about stating what the fix was for other's future reference?

    thanks.

  7. #7
    atzdgreat is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2019
    Posts
    27
    sorry about that.. i made what you said. me.repaint before next i... thank you again

    Code:
    Private Sub Form_Load()
        Dim ProgBar  As MSComctlLib.ProgressBar
        Me.lblPerc.Caption = "0%"
        Me.lblSaveCaption.Caption = "Preparing Datas"
        
        Set ProgBar = Me.progBar1.Object
        ProgBar.BorderStyle = ccNone
        ProgBar.Appearance = ccFlat
        ProgBar.Min = 0
        ProgBar.Value = 0
        Set ProgBar = Nothing
        
        Me.TimerInterval = 1
    End Sub
    
    
    Private Sub Form_Timer()
        Call SaveStaffAttendance
    End Sub
    
    Private Sub SaveStaffAttendance()
        Dim LV  As MSComctlLib.ListView
        Dim NewProgBar As MSComctlLib.ProgressBar
    
        Set LV = Form_StaffTimeAttendance.ListView2.Object
        NewProgBar.Max = LV.ListItems.Count
        For i = 1 To LV.ListItems.Count
    
            'Some Code Here
    
            Me.lblSaveCaption.Caption = "Updating Staff [" & LV.ListItems(i).Text & "] " & LV.ListItems(i).SubItems(1)
            NewProgBar.Value = NewProgBar.Value + 1
            Me.lblPerc.Caption = Format(NewProgBar.Value / NewProgBar.Max * 100, "##0") & "%"
            Me.Repaint '<------ perfect!
        next i
        Me.TimerInterval = 0
    End Sub

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Great! Thanks for clarifying. Glad I could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using Textbox or Label as Progress Status Field
    By EddieN1 in forum Programming
    Replies: 2
    Last Post: 11-06-2017, 04:53 PM
  2. Replies: 2
    Last Post: 03-07-2017, 02:42 AM
  3. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  4. Replies: 5
    Last Post: 10-04-2013, 12:30 AM
  5. Replies: 1
    Last Post: 09-05-2012, 07:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums