Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

progress bar in macro populating sheets from a selected listbox value

Posted on 2014-01-22
2
Medium Priority
?
427 Views
Last Modified: 2014-01-29
folks

I have a listbox where if a item is selected in the listbox , a call gets made to the oracle db and downloads the associated records into sheet2

how though do I call up a progress bar to show status on the time when data is being downloaded and populated into the sheet

keen for your thoughts

here is my code:


Private Sub ListBox1_Click()

'Dim r As Long
'r = Sheet1.Range("A1").Offset(Sheet1.Rows.Count - 2, 0).End(xlUp).Row
   
   
MsgBox "Select * from Workorder where  " & ListBox1.Value & ""
Sheets(2).Range("A1").Value = "Select * from projects where " & ListBox1.Value
Sheets(2).Range("A3:IV65536").ClearContents

    Dim strConOracle As String
    Dim strTemp As String
    Dim oConOracle, oRsOracle
    Dim strSQL As String
    Dim lngCount As Long
    Dim strCount As String
    Dim DBNAME As String
    Dim HOST As String
    Dim ORACLE_USER_NAME As String
    Dim ORACLE_PASSWORD As String
    ORACLE_PASSWORD = Range("D2").Value
    DBNAME = Range("A2").Value
    HOST = Range("B2").Value
    ORACLE_USER_NAME = Range("C2").Value

   
    strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)"
    strConOracle = strConOracle & "(HOST=" & HOST & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & DBNAME
    strConOracle = strConOracle & "))); uid=" & ORACLE_USER_NAME & " ;pwd=" & ORACLE_PASSWORD & ";"
    Set oConOracle = CreateObject("ADODB.Connection")
    Set oRsOracle = CreateObject("ADODB.RecordSet")
    oConOracle.Open strConOracle
   
 
strSQL = "SELECT task,description,owner from projects WHERE  " & ListBox1.Value & ""

   
   
    Set oRsOracle = oConOracle.Execute(strSQL)

   
    lngCount = 2
       
        Do While Not oRsOracle.EOF
       
 
       
            DoEvents
            lngCount = lngCount + 1
            strCount = Trim(Str(lngCount))
       
           
            If Not IsNull(oRsOracle.Fields(0).Value) Then
                strTemp = oRsOracle.Fields(0).Value
           Else
                strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Not Captured"
            Sheet2.Range("A" & strCount).FormulaR1C1 = strTemp
           
           
           
            If Not IsNull(oRsOracle.Fields(1).Value) Then
                strTemp = oRsOracle.Fields(1).Value
            Else
                strTemp = ""
           End If
            If strTemp = "" Then strTemp = "Not Populated"
            Sheet2.Range("B" & strCount).FormulaR1C1 = strTemp
           
           
           
            If Not IsNull(oRsOracle.Fields(2).Value) Then
                strTemp = oRsOracle.Fields(2).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Sched Start"
            Sheet2.Range("C" & strCount).FormulaR1C1 = strTemp
           
       
       
            If Not IsNull(oRsOracle.Fields(3).Value) Then
                strTemp = oRsOracle.Fields(3).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "No Sched Finish"
            Sheet2.Range("D" & strCount).FormulaR1C1 = strTemp
           
           
            If Not IsNull(oRsOracle.Fields(4).Value) Then
                strTemp = oRsOracle.Fields(4).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Status"
            Sheet2.Range("E" & strCount).FormulaR1C1 = strTemp
           
            oRsOracle.MoveNext
    Loop
    oConOracle.Close
    Set oRsOracle = Nothing
    Set oConOracle = Nothing




r
0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 39801960
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 1500 total points
ID: 39801973
actually i think i misread your q somewhat.....

have a look at the second link...

it uses displays a userform while the process occurs and this form can be updated to show progress if desired. then unloaded.
to test, create a new userform <MyProgress> and add a text box to it

    MyProgress.Show
    lngCount = 2
        
        Do While Not oRsOracle.EOF
            DoEvents
            lngCount = lngCount + 1
            if lngCount Mod 10 = 0 then
                   MyProgress.textbox1.text = MyProgress.textbox1.text & "#"
            end if

            '......

       loop
      MyProgress.Hidden = true

Open in new window


it should show a line of ### move as progress occurs.  Can add an abort button if needed.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

705 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