Solved

Progress Meter (Updating Form Labels In Form View)

Posted on 2004-09-23
7
420 Views
Last Modified: 2012-06-27
Hello,

I have made several scripts using VB that process various data in MSAccess- check some boxes here, add notes to this text box, and so on based on conditions from a query.  They all work exactly how I want them to, but some of them run for a rather long time and I would like to be able monitor the progress of the scripts.

My first thought was to create a Form right before the process starts and after every iteration of the process, update a label on the form that says, "12 out of 99,456 records processed." or possibly even draw a small blue rectangle and keep increasing the size of it to illustrate the progress like other programs often do.

I have relatively little experience in VB programming, but I know this would be a piece of cake in Java.  When I tried implementing this in VB I found that I can't make any modifications to a Form while in Form View.  Is there a way around this?

I also considered using a TextBox (surely this can be changed in FormView) and disguising it as a Label since I think TextBoxes look really tacky to display info that can't be modified.  I ran into a problem here too, though.  Here's what I did:

Dim strFormName As String
Dim frmProgress As Form
Dim cl As Control
Set frmProgress = CreateForm()
frmProgress.NavigationButtons = False
frmProgress.RecordSelectors = False
strFormName = frmProgress.name
Set cl = CreateControl(strFormName, acTextBox, acDetail, "", "", 100, 100, 5000, 300)
DoCmd.OpenForm (strFormName) ' open FormView
cl.Text = "Connecting to Database"

I get a: Run-time error '2467' Application-defined or object-defined error on the last line listed here.

Surely there is someone out there who has done this kind of thing before, and surely there is a way to implement this.  I'm very close to scrapping everything I've done using the MS Access VB and just starting over with the front end with a platform that allows more control.  Am I getting frustrated because I don't know what I'm doing or is it because MS VB is just not very flexible?

Thanks for any ideas you may have.
-Shannon
0
Comment
Question by:rhinoceroshead
7 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 100 total points
Comment Utility
> Is there a way around this?

You cannot create or delete controls if the formis not in design view. Most other properties can be changed while the form is in any view.

Just create a label on the form manually. Save the form and then change the label's Caption property in code.

VBA is extremely flexible, but it has a different design methodology from Java. More or less anything that can be achieved in any event dirven, design language can be achieved in VBA but creating controls on the fly is something that you don't generally do with VBA. You usually use pre-created controls.
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
If you need a control on the form to be displayed under certain circumstances, create the control in Design view, giving it a FALSE value for the Visible property.  This gives you the opportunity to set the value of the control before the user sees it, and to determine if and when the user will see it through code.  This is the closest you will get to dynamic controls.

If you would like some examples, create a switchboard in Access using the Switchboard Manager utility, and examine the code it generates.
0
 
LVL 36

Expert Comment

by:SidFishes
Comment Utility
this is what i use for feedback on record processing  (export in this case) It updates a label on the form based on total to process and already processed...might be adaptable for you...

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim x, y
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = pubstrConnect
    strSQL = "EXEC dbo.maintFindUnExportedOrders " 'find orders for export
    cnn.Open
    Set rst = New ADODB.Recordset
    With rst
        .CursorLocation = adUseClient
        .Open Source:=strSQL, _
                ActiveConnection:=cnn, _
                CursorType:=adOpenDynamic, _
                LockType:=adLockOptimistic

       .MoveFirst
       While x < .RecordCount
       pubOrderID = !OrderID
       Call ExportEm 'a procedure which does the export
       .MoveNext
          x = x + 1
          y = .RecordCount - x
          Me!lblProcessed.Caption = y & " Records Left In Queue"
          Repaint
          Refresh
          Wend
       
          .Close
    End With

    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
   

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:rhinoceroshead
Comment Utility
I'm awarding the points to shanesuebsahakarn because the solution to my problem was contained in that reply.  The code that I posted was not working because I had not yet saved the form, and apparently you can't change the Captions on a label that has not yet been saved.

I still don't think VB is very flexible.  Java is much more consistent about how to create and update objects and VB is extremely restrictive in that you can't add controls to existing forms.  VB just doesn't seem intuitive to me.  I feel like I have to look up somebody else's code to learn how to do anything.  For example, to create a new form with a control on it, I would assume you could just do this:

Dim newForm as Form
Dim newControl as Control

Set newForm = new Form
Set newControl = new Control
newForm.addControl(newControl)

But that won't work at all.  You have to use Application.CreateControl() to make the control.  What's the point of the 'new' keyword if you can't universally create a new object with it?  Some objects you can and some you can't.  If it were consistent then the learning curve wouldn't be nearly so steep.

Thanks for the help, and I'm really impressed by the quick responses!

Shannon
0
 
LVL 36

Expert Comment

by:SidFishes
Comment Utility
welcome to the wonderful wolrd of vba and vb...

" If it were consistent then the learning curve wouldn't be nearly so steep."...and vb and vba wouldn't be Number 1 and number 2 in questions asked at EE ;)

0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
Again, it's a design methodology and understanding. The New keyword does work with forms, but it is used to create a new *instance* of an *existing object*. There should almost never be a situation where you ever need to create a form "on the fly". The keywords are not necessarily analogous to an action you would perform in design view.

Language and application design environments don't all work in the same way, and you can't expect them to. Many of us here could achieve almost anything in VBA that can be achieved with other languages and you'll learn the appropriate methods as you progress with it.
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
I should really get my terminology right:
a new instance of an *existing object definition* (or class, if you prefer)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now