Solved

Progress bar question

Posted on 2006-11-10
4
187 Views
Last Modified: 2010-04-30
Hi,

I have this code:

        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)
       
        j = 0
       
        For i = 1 To 12
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        xlApp.Quit
       
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True


How can I show progress bar while this code is working? I'm using  Microsoft Common Controls Progress Bar. Thanks.
0
Comment
Question by:RealSnaD
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17916455
you put the progress bar on the form, say barProgress, and have it invisible


        barProgress.Min = 0
        barProgress.Value = 0
        barProgress.Max = 12
        barProgress.visible = true
        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)
       
        j = 0
       
        For i = 1 To 12
           barProgress.Value = i
           doevents
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        xlApp.Quit
       
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True
       barProgress.visible = false
0
 
LVL 7

Author Comment

by:RealSnaD
ID: 17916628
Progressbar becomes visible but nothing is happening in it. Then it just disappears.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17916722
did you put the line doevents?
note that working on only 12 cells should not really need a progress bar that will be done very fast anyhow.


        barProgress.Min = 0
        barProgress.Value = 0
        barProgress.Max = 7
        barProgress.visible = true
        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        barProgress.Value = 1
        doevents
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        barProgress.Value = 2
        doevents
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)

        barProgress.Value = 4
        doevents
       
        j = 0
       
        For i = 1 To 12
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        barProgress.Value = 5
        doevents
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        barProgress.Value = 6
        doevents
        xlApp.Quit
       
        barProgress.Value = 7
        doevents
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True
       barProgress.visible = false
0
 
LVL 7

Author Comment

by:RealSnaD
ID: 17917225
Perfect! Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 50
maro to copy and paste from one worksheet to another based on a condition 11 48
TT Auto Dashboard 13 85
Added a column screws up code 5 50
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

896 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

13 Experts available now in Live!

Get 1:1 Help Now