cara membuat laporan dari database access 2003 (MDB)
Imports System.Data.OleDb
Public Class Form1
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Sub koneksi()
conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbpenjualan.mdb")
conn.Open()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CrystalReportViewer1.SelectionFormula = "totext({tblpenjualan.tanggal})='" & dtp1.Text & "'"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
CrystalReportViewer1.SelectionFormula = "{tblpenjualan.tanggal} in date ('" & dtp2.Text & "') to date ('" & dtp3.Text & "')"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
CrystalReportViewer1.SelectionFormula = "month({tblpenjualan.tanggal}) =(" & Month(dtp4.Text) & ") and year({tblpenjualan.tanggal}) =(" & Year(dtp4.Text) & ")"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
CrystalReportViewer1.SelectionFormula = "year({tblpenjualan.tanggal}) =(" & Year(dtp4.Text) & ")"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
koneksi()
cmd = New OleDbCommand("select faktur from tblpenjualan", conn)
dr = cmd.ExecuteReader
Do While dr.Read
ListBox1.Items.Add(dr(0))
Loop
cmd = New OleDbCommand("select distinct nama_customer from tblpenjualan,tblcustomer where tblpenjualan.kode_customer=tblcustomer.kode_customer", conn)
dr = cmd.ExecuteReader
Do While dr.Read
ListBox2.Items.Add(dr(0))
Loop
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
CrystalReportViewer1.SelectionFormula = "{tblpenjualan.faktur}='" & ListBox1.Text & "'"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
CrystalReportViewer1.SelectionFormula = "{tblcustomer.nama_customer}='" & ListBox2.Text & "'"
CrystalReportViewer1.ReportSource = "master.rpt"
End Sub
End Class