koneksi VB dengan Crystal Report

laporan dengan crystal report sangat membantu kita untuk memperbanyak lembaran, dengan crystal report pekerjaan jadi serba mudah dan ringan. maka saya akan memberitahu kode visual basic yang dikoneksikan dengan crystal report

laporan dengan crystal report sangat membantu kita untuk memperbanyak lembaran, dengan crystal report pekerjaan jadi serba mudah dan ringan. maka saya akan memberitahu kode visual basic yang dikoneksikan dengan crystal report
copy paste kode ini kedalam view code:
Option Explicit
‘deklarasi objDAO,objDataBase,ObjRecordset sebagai objek
Dim ObjDAO As Object
Dim ObjDataBase As Object
Dim ObjRecordSet As Object
Private Sub OpenDataMDBBase()
Set ObjDAO = CreateObject(“DAO.DBEngine.35”)
‘membuka file yang disimpan
Set ObjDataBase = ObjDAO.OpenDatabase(“C:\Temp\EmpData.mdb”)
‘membuka record
Set ObjRecordSet = ObjDataBase.OpenRecordset(“DataBaseProject”)
End Sub
Private Sub CmdEnd_Click()
‘keluar
End
Unload Me
End Sub

Private Sub cmdGo_Click()
‘On Error GoTo ErrorHandalar
Screen.MousePointer = vbHourglass
Dim strQryString As String
If optName.Value = True Then
Dim strTempQryString As String
Dim I As Integer
Dim J As Integer
J = 1
strTempQryString = “{DatabaseProject.EmployeeName} =”
If lstEmployee.SelCount > 1 Then
For I = 0 To lstEmployee.ListCount – 1
If lstEmployee.Selected(I) = True Then
If J = 1 Then
strQryString = strTempQryString & “‘” & lstEmployee.List(I) & “‘”
J = J + 1
Else
strQryString = strQryString & ” Or ” & strTempQryString & “‘” & lstEmployee.List(I) & “‘”
End If
End If
Next I
Else
strQryString = strQryString & strTempQryString & “‘” & lstEmployee.List(lstEmployee.ListIndex) & “‘”
End If
‘memulai with crystal report
With CrystalReport1
.ReportFileName = App.Path & “\EmpDetails.rpt”
.Connect = App.Path & “\EmpData.mdb”
.DiscardSavedData = True
.RetrieveDataFiles
.ReportSource = 0
.SQLQuery = “Select * from DataBaseProject order by EmployeeName”
.ReportTitle = “Employee Details Report”
.Destination = crptToWindow
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
If strQryString <> “{DatabaseProject.EmployeeName} =’Select All'” Then
.SelectionFormula = strQryString
End If

.Action = 1
‘mengakhiri with
End With
End If
If optDOB.Value = True Then
If txtFromDate.Text <> “” And txtToDate.Text <> “” Then
strQryString = “{DatabaseProject.EmployeeDOB} >= #” & Format(txtFromDate.Text, “mm/dd/yyyy”) & “# And {DatabaseProject.EmployeeDOB} <= #” & Format(txtToDate.Text, “mm/dd/yyyy”) & “#”
End If
With CrystalReport1
.ReportFileName = App.Path & “\EmpDetails.rpt”
.Connect = App.Path & “\EmpData.mdb”
.DiscardSavedData = True
.RetrieveDataFiles
.ReportSource = 0
.SQLQuery = “Select * from DataBaseProject order by EmployeeName”
.ReportTitle = “Employee Details Report”
.Destination = crptToWindow
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.SelectionFormula = strQryString
.Action = 1
End With
End If
Screen.MousePointer = vbDefault
Exit Sub
ErrorHandalar:
MsgBox CStr(Err.Number) + Err.Description
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Load()
Call CopyMdbFileInReportLocation
Call OpenDataMDBBase ‘//membuka MDB Databse
Call FillListBox ‘//memanggil filllistbox
optName.Value = True
End Sub
Private Sub FillListBox()
lstEmployee.AddItem “Select All”
Do While Not ObjRecordSet.EOF
lstEmployee.AddItem ObjRecordSet.Fields(“EmployeeName”)
ObjRecordSet.MoveNext
Loop
lstEmployee.Selected(0) = True
End Sub
Private Sub CopyMdbFileInReportLocation()

Dim fso As Object, f As Object, MyFile As Object
Set fso = CreateObject(“Scripting.FileSystemObject”)
If Not (fso.FolderExists(“C:\Temp”)) Then
Set f = fso.CreateFolder(“C:\Temp”)
End If
If Not (fso.FileExists(“C:\Temp\EmpData.mdb”)) Then
Set MyFile = fso.GetFile(App.Path & “\EmpData.mdb”)
MyFile.Copy (“C:\Temp\EmpData.mdb”)
End If
If (fso.FileExists(App.Path & “\EmpData.mdb”)) Then
fso.DeleteFile (App.Path & “\EmpData.mdb”)
End If
End Sub

One Response to “koneksi VB dengan Crystal Report”

  1. programmervb Says:

    hi..thank’s for your code . its great

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: