Solved

progress bar in macro populating sheets from a selected listbox value

Posted on 2014-01-22
2
422 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 500 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

626 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