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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

progress bar problem 1

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
GB
I have a form which instantiates a custom class which uses OLE to go and get loads of info from another application.

When the user hits the command button, the code goes off and builds the object which can take a long time.

I have used progress bars successfully but only when the code is inside the form and you can increment the bar at the end of each loop.

Is it possible to display a progress bar on the form to show the progress of the class module code executing?
 
Thanks mp9

I did not know you could do that. However, I would like something a little more "in your face" as some of the users here would never notice the status bar.

Combined with the DoCmd.Hourglass True will probably suffice but if anyone has another solution, I would be glad to here it.
 
How are ya NSNewey . . . . .

[ol][li]The [blue]ProgressBar[/blue] itself has to go on a form anyway.[/li]
[li]In your custom class (I believe your talking a [blue]custom class module[/blue]), there's no reason you can't control the bar from it. You just have to reference the form and Bar properly. Something like this as part of your class code:
Code:
[blue]   Dim ctl As Control
   
   Set ctl = Forms!FormName![purple][b]ProgressbarName[/b][/purple]
   
   Do
      [green]'your running class code[/green]
      ctl = ctl + 1
   Loop Until [purple][b]YourExpression[/b][/purple]
   
   Set ctl = Nothing[/blue]
[/li][/ol]
Your biggest problem may be determining [blue]what value to set as max for the bar[/blue] so it runs the full length without overshooting.

Calvin.gif
See Ya! . . . . . .
 
Thanks TheAceMan1

I'll give that a go... The class module executes a known number of statements so I can get the max value from there.
 
NSNewey . . . . .

Don't know if you'll need this or not, but decided to post it anyway.

There are three main operational attributes for a Progress Bar:

[purple]Min[/purple], which defaults to zero and usually needs no setup.

[purple]Max[/purple], the full count of the bar, usually set by the programmer . . . AKA . . . You!

[purple]Value[/purple] (and the most important), the current value of the bar, >= min & <= max that is [purple]setup/enumerated by you![/purple]


To setup the Form & ProgressBar, in a new form in design view, on the menubar click Insert - ActiveX Control..., scroll to and select [blue]Microsoft ProgressBar Control, version 6[/blue]. Click OK.

Size the bar to your liking then, right-click the bar - [blue]ProgCtrl Object[/blue] - [blue]Properties[/blue]. At the bottom you'll see the combobox for the [blue]Scrolling[/blue] property. Select [purple]Smooth[/purple]. Click OK.

Now set the following properties for the form:

[blue]ScrollBars [purple]Neither[/purple]
Record Selectors [purple]No[/purple]
Navigation Buttons [purple]No[/purple]
Auto Resize [purple]Yes[/purple]
Auto Center [purple]Yes[/purple]
Border Style [purple]Dialog[/purple]
Min Max Buttons [purple]None[/purple]
Caption [purple]Empty/No Value[/purple]
PopUp [purple]Yes[/purple]
Modal [purple]Yes[/purple][/blue]

Save/close the form

Use the following to open the form:
Code:
[blue]   DoCmd.OpenForm "YourFormName"
   DoEvents [green]'Allows ActiveX Control to fully refresh.[/green][/blue]
The following is an example of opening, enumerating, and closing the form:
Code:
[blue]   Dim frm As Form, ctl As Control, n As Long
   
   DoCmd.OpenForm "[purple][b]ProgressBarFormName[/b][/purple]"
   DoEvents [green]'Allows ActiveX Control to fully refresh.[/green]
   
   Set frm = Forms![purple][b]ProgressBarFormName[/b][/purple]
   Set ctl = frm![purple][b]ProgressBarName[/b][/purple]
   
   frm.Caption = "Down Loading Data!"
   ctl.Max = 1000 'Set max count for the bar
   
   [green]'Sample enumeration. Your enumeration code would go here.[/green]
   For n = 1 To 1000
      ctl = n
   Next
   
   DoCmd.Close acForm, "[purple][b]ProgressBarFormName[/b][/purple]"
   
   Set ctl = Nothing
   Set frm = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
I too have been trying for ages to make this work - using that code, it now does... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top