X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Problem repainting form    
 
   
tinkythomas
post Aug 11 2009, 07:09 AM
Post #1

UtterAccess Guru
Posts: 538
From: England



Hi,
I have created a progress bar form and call it from various procedures. The problem I'm having is if a query takes some time to run then the progress bar doesn't repaint for any subsequent calls.
The code in the form module is...
CODE
Option Compare Database
Option Explicit
Public Function PctMeter(vAmt As Variant, vTotal As Variant)
    Dim sngPct As Single    'declare variables
    On Error GoTo PctMeter_Error
    sngPct = vAmt / vTotal
    If sngPct <= 1 Then
        Me!baselbl.Caption = Int(sngPct * 100) & "%"
        Me!lblmeter.Width = CLng(Me!baselbl.Width * sngPct)
    Else
        Me!baselbl.Caption = "Greater than 100% - Check your amounts"
        Me!lblmeter.Width = CLng(Me!baselbl.Width * 1)
    End If
    Me!lblmeter.BackColor = 16711680
    Select Case sngPct    'change the caption font color to white if greater than 50%
    Case Is < 0.5
        Me!baselbl.ForeColor = 0
    Case Else
        Me!baselbl.ForeColor = 16777215
    End Select
    Me.Repaint
PctMeter_Exit:
    Exit Function
PctMeter_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure PctMeter of VBA Document Form_frmProgressBar"
    Resume PctMeter_Exit
End Function
Public Sub Form_Open(Cancel As Integer)
    Dim strAviFile As String    'declare variables
    On Error GoTo Form_Open_Error
    strAviFile = Application.CurrentProject.Path & "\HGLASS_T.avi"    'path to .avi file
    With Me.Animation0
        .Visible = True
        .AutoPlay = True
        .Open strAviFile    'play file
    End With
Form_Open_Exit:
    Exit Sub
Form_Open_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Open of VBA Document Form_frmProgressBar"
    Resume Form_Open_Exit
End Sub

Oalso have a animated hourglass that is opened when the form opens. This freezes aswell if and when the query from the calling procedure hangs.
I call the form like so...
CODE
Call Form_frmProgressBar.PctMeter(16, 18)      'update progress meter
        Form_frmProgressBar.statuslbl.Caption = "Doing something"

This doen't always happen, only if a query takes some time to complete. I have tried turning off the access hourglass (this appears if the query takes time to complete) with Do.Cmd Hourglass False but it still appears.
Anybody have any ideas or suggestions?
Thanks,
Go to the top of the page
 
+
hopper20
post Aug 11 2009, 11:22 AM
Post #2

UtterAccess Addict
Posts: 197
From: Michigan



Hi Chris
One suggestion is to add the line:
DoEvents
somewhere on the module code. I'm going to assume the stand-alone module is the code used to loop, so I would say, maybe, right after the line
On Error GoTo PctMeter_Error
Hope that helps you
Go to the top of the page
 
+
tinkythomas
post Aug 11 2009, 02:28 PM
Post #3

UtterAccess Guru
Posts: 538
From: England



Thanks for the reply. I have read Access help regarding the DoEvents function. It says this passes control to the operating system. I assume that given the number of times the function PctMeter maybe called from a procedure, this will cause no problems?

Do I remove the line...
Me.Repaint
I guess this is not needed with DoEvents?

I will try this when I'm back in the office tomorrow and let you know how I get on.

Thanks again
Edited by: tinkythomas on Tue Aug 11 16:10:03 EDT 2009.
Go to the top of the page
 
+
tinkythomas
post Aug 12 2009, 02:52 AM
Post #4

UtterAccess Guru
Posts: 538
From: England



I replaced the line...
Me.Repaint
with
DoEvents
And now everything seems to run smoothly. I have repeatedly tested the procedure that was causing problems and it now seems to be ok.
Thank you very much for your help.
Regards,
Go to the top of the page
 
+
hopper20
post Aug 12 2009, 06:56 AM
Post #5

UtterAccess Addict
Posts: 197
From: Michigan



Not a problem. I use a similar program, and run into the same problem of getting the "status" bar to update or repaint properly.
Glad you got it working
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 17th December 2014 - 09:21 PM