Sub export()
progress.Show
'Misal Nie querynya :
sql_export = "select * from barang"
'Yang dibawah ini untu progress bar-nya
progress.ProgressBar1.Value = i
Set AppExcel = New Excel.Application
Set ExcelWBk = AppExcel.Workbooks.Add
Dim ColField As Collection
Dim jmlField As Integer
Set ColField = New Collection
Set ExcelWS = ExcelWBk.Worksheets.Add
Set expo = New ADODB.Recordset
expo.Open sql_export, konek, adOpenDynamic, adLockOptimistic
For jmlField = 0 To expo.Fields.Count - 1
ExcelWS.Cells(1, jmlField + 1) = expo.Fields(jmlField).Name
ColField.Add expo.Fields(jmlField).Name
DoEvents
Next jmlField
Dim Pos As Long
Pos = 2
terong = expo.RecordCount
If Not expo.EOF Then
expo.MoveFirst
While Not expo.EOF
For jmlField = 1 To ColField.Count
test = expo(ColField(1))
ExcelWS.Cells(Pos, jmlField) = expo(ColField(jmlField))
ato = (((Pos - 1) * 100) / terong)
progress.ProgressBar1.Value = Val(ato)
progress.Label2.Caption = Val(ato)
Next jmlField
Pos = Pos + 1
expo.MoveNext
DoEvents
Wend
End If
expo.Close
If Err <> 0 Then
Bego = True
Err.Clear
End If
AppExcel.Visible = True
Unload progress
End Sub
Tidak ada komentar:
Posting Komentar