Question

I have some code at the moment to draw a graph based on the values of a series of text boxes on an access form.

I’m happy with the code and how it works but I’m not convinced that it is the most efficient way of doing this. The graph takes about 1.2 seconds to redraw each time. The form is unbound so it is just getting the values from the text boxes. Just to check I got it to loop through and dump the text boxes values to debug.print and that did it instantly so it cant be that.

I suspect that it is trying to redraw the graph after each value is added. Is there a quicker way of doing this in VBA or am I stuck with it?

'**************************
        '** Draw the Call Deviation graph **
        '**************************
        .cells(1, 1) = "Start Time"
        .cells(1, 2) = "Deviation"
        lRT_actual = 0
        lRT_forecast = 0
        For i = 1 To 48
            lRT_actual = lRT_actual + Me.Controls("txtActual_" & i)
            lRT_forecast = lRT_forecast + Me.Controls("txtForecast_" & i)
            .cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")

            .cells(i + 1, 2) = lRT_actual - lRT_forecast

            If Me.acxProgress_bar.Value + 2 < 100 Then
                Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
            Else
                Me.acxProgress_bar.Value = 90
            End If
        Next i

Thanks for your help

Was it helpful?

Solution

Would it be possible for you to add the values to a table and graph that?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top