Create Report with Ms excell is alternative way for reporting on Visual Basic 6.0, maybe that is the simple way to create report, we just make reference on project with microsoft data access 2.5 or higher. the code like below;
Public vExcel As Excel.Application
Public Sub pOpenExcel()
Set vExcel = Nothing
Screen.MousePointer = vbHourglass
Set vExcel = CreateObject("Excel.Application")
Screen.MousePointer = vbDefault
End Sub
Private Sub Command1_Click()
Dim nb As Integer, startRow As Integer
Dim rsprint As ADODB.Recordset
recordset_conn rsprint, "select * from books"
If rsprint.RecordCount = 0 Then Exit Sub
Call pOpenExcel
vExcel.Workbooks.Add (App.Path & "\report.xlt")
vExcel.WindowState = xlMaximized
vExcel.Visible = True
startRow = 6
With vExcel.ActiveSheet
While Not rsprint.EOF
nb = nb + 1
'.cells(startRow + nb, 1).Value = nb
.Cells(startRow + nb, 1).Value = rsprint.Fields("title")
.Cells(startRow + nb, 2).Value = rsprint.Fields("author first name")
.Cells(startRow + nb, 3).Value = rsprint.Fields("category")
.Cells(startRow + nb, 4).Value = rsprint.Fields("price")
rsprint.MoveNext
Wend
End With
End Sub
For Complete Code you can download in here


0 komentar:
Post a Comment