Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading bar....

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hello,

I have a procedure that runs for quite a long time. So what I want to do is to show a loading bar or on the status bar have a counter incrementing, so user would know that the procedure is actually running and application is not frozen.

Please suggest any solution.

I'd appreciate your help.

Thanks
 
sabavno,

Try looking in the Help files for acSysCmdSetStatus.

Wayne
 
Here's a snippet to look at. For the status bar you need to get a MAX value and some text to initialize it with, then increment it during the process:
Code:
Function LinkTables() As Boolean
On Error GoTo ErrHandler

  Dim lngTotal    As Long
  Dim lngCount    As Long
  Dim obj         As Object
    
  lngTotal = mcolUnprocessed.Count
  DoCmd.Hourglass True

  SysCmd acSysCmdInitMeter, "Linking tables, please wait...", lngTotal

  For Each obj In mcolUnprocessed

    '...do looping code...

    lngCount = lngCount + 1
    SysCmd acSysCmdUpdateMeter, lngCount
  Next obj

  LinkTables = True
   
ExitHere:
  SysCmd acSysCmdRemoveMeter
  DoCmd.Hourglass False
  Exit Function
ErrHandler:
  MsgBox Err & "-" & Err.Description
  Resume ExitHere
End Function
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
What is mcolUnprocessed represent in your code and where should I declare it?
 
Sabavno,

I had the same question you had for a long time (I had a long time to wait when opening a quite complex report on 30.000 records and grouped on 4 ways...)

Instead of calculating the MAX value using the SYS... stuff, I open a small form "please wait..." which closes when the task is done.

My "Please Wait..." form contains a textbox to hold the text in. I also found a small ActiveX on the Net "vCodersanimation.ocx", which makes it possible to open some standard windows-animation dll's to show on your form (eg. the animation you see when copying a folder,...)

Here is the code I use for this :

Private Sub Btn_Filter_Click()

On Error GoTo Err_Btn_filter_Click

DoCmd.OpenForm "frm_wait"
Me.Visible = False
DoCmd.RepaintObject acForm, "frm_wait"


DoCmd.OpenReport "my reportname here", acViewPreview DoCmd.Close acForm, "frm_wait"

While SysCmd(acSysCmdGetObjectState, acReport, "my report here") = acObjStateOpen
DoEvents
Wend

Me.Visible = True

Exit_Btn_filter_Click:
Exit Sub

Err_Btn_filter_Click:
MsgBox Err.Description
Resume Exit_Btn_filter_Click
End If


End Sub

Regards,

Peter
 
The mcolUnprocessed was just a module-level collection of table links I used for demonstration purposes. The point is that you have to know in advance what to initialize the status bar to, and be able to increment it at specific points in your loop.

If that isn't possible, then pdtit's solution is another way to handle it.

I've used simple status-bar animations before when I didn't know how long a process would take by changing it every half second using a hidden form. Just make a plain form and set its Timer Interval to 500 (half a second), open it as acHidden:

Code:
  DoCmd.OpenForm "frmStatusBar", acNormal, , , , acHidden

and put something like this in its Timer() event:

Code:
  Private Sub Form_Timer()
    Static intCtr As Integer
    Dim strMsg As String
 
    intCtr = intCtr + 3

    If intCtr > 36 Then
      intCtr = 3
    End If
  
    strMsg = "Processing, please wait " & String(intCtr, "|")
  
    SysCmd acSysCmdSetStatus, strMsg
  
  End Sub

Just remember to reset the status bar when you close the hidden form by putting code in its Unload() event:

Code:
  Private Sub Form_Unload(Cancel As Integer)
    SysCmd acSysCmdClearStatus
  End Sub

VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top