Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21278

How to show recordset MySQL data fast(er) in excel?

$
0
0
Hi There,
Please see below code.
it takes about 0.01 seconds to get data from the MySQl database
It takes a lot longer to fill every single cell with the proper value
does any faster way exist to fill cells with the proper data?
tried playing around with the getstring option as this holds ALL data but couldn't find a proper way to use this and show data properly

Code:

  mySQL = ""
    mySQL = mySQL & "SELECT ID, txtJPost, txtVolgnr, txtShipmentID, txtDateInvoice, txtAmountex, txtcur, txtROE, txtPaid"
    mySQL = mySQL & " FROM invoicedb"
    mySQL = mySQL & " WHERE txtShipmentID IN "
    mySQL = mySQL & "(SELECT shipmentID FROM shipmentdb "
    mySQL = mySQL & "WHERE InputDate >= '" & Year(Sheet1.Range("E10").Value) & "-" & Month(Sheet1.Range("E10").Value) & "-"
    mySQL = mySQL & Day(Sheet1.Range("E10").Value) & "'"
    mySQL = mySQL & " AND InputDate <= '" & Year(Sheet1.Range("G10").Value) & "-" & Month(Sheet1.Range("G10").Value) & "-"
    mySQL = mySQL & Day(Sheet1.Range("G10").Value) + 1 & "')"
    mySQL = mySQL & " ORDER BY txtShipmentID"
    'MsgBox mySQL
    myRS.Source = mySQL
    Set myRS.ActiveConnection = myconn
    myRS.CursorLocation = adUseClient
    myRS.Open
    Do While Not myRS.EOF
      Sheet2.Range("A" & Step1).Value = myRS.Fields("txtShipmentID").Value
      Sheet2.Range("B" & Step1).Value = "B"
      Sheet2.Range("C" & Step1).Value = myRS.Fields("ID").Value
      Sheet2.Range("D" & Step1).Value = myRS.Fields("txtDateInvoice").Value
      Sheet2.Range("E" & Step1).Value = myRS.Fields("txtVolgNr").Value
      Sheet2.Range("F" & Step1).Value = Replace(myRS.Fields("txtAmountEX").Value, ",", ".")
      Sheet2.Range("F" & Step1).Value = Sheet2.Range("F" & Step1).Value * -1
      Sheet2.Range("G" & Step1).Value = myRS.Fields("txtROE").Value
      Sheet2.Range("H" & Step1).Value = myRS.Fields("txtPaid").Value
      Sheet2.Range("I" & Step1).Value = myRS.Fields("txtCUR").Value
      Sheet2.Range("J" & Step1).Value = myRS.Fields("txtJPost").Value
      If myRS.Fields("txtCUR").Value <> "EUR" Then
        Sheet2.Range("F" & Step1).Value = myRS.Fields("txtAmountEX").Value * CDec(myRS.Fields("txtROE").Value)
        Sheet2.Range("F" & Step1).Value = Sheet2.Range("F" & Step1).Value * -1
      End If
      myRS.MoveNext
      Step1 = Step1 + 1
    Loop
  myRS.Close
  myconn.Close

Appreciated!

Viewing all articles
Browse latest Browse all 21278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>