Rabu, 25 Desember 2013

Cara Koneksi VB 6.0 dan Cristal Report Dengan Database Acces Berpassword


Artiker berikut ini  merupakan  lanjutan dari artikel sebelunya tentang Cara membuat Database MS Acces berpassword dengan MS Office 2010 dan Cristal Report dengan DB Acces Berpassword Berikut ini saya membuatkan Contoh project untuk memudahkan anda semua dalm memperlajarinya Langkan pertama buat rancangan form sebagi berikut

Copykan kode berikut pada Form yang sudah anda rancang
Codenya :
Option Explicit
Dim rsPerson As New ADODB.Recordset
Dim Db As Connection
'-------------------
Public conn As New ADODB.Connection
Dim Database As Connection
Dim WithEvents rs As Recordset
Sub konek()


Set Database = Nothing
Set Database = New Connection
Database.CursorLocation = adUseClient
Database.Open "PROVIDER=MSDataShape;Data PROVIDER= microsoft.jet.oledb.4.0;Data Source=" _
& App.Path & "\Database1.mdb;Jet OLEDB:Database Password=rahman; "
End Sub


Private Sub CmdCetakByTgl_Click()
If DTPicker2.Value < DTPicker1.Value Or DTPicker1.Value > DTPicker2.Value Then
MsgBox "Tanggal terbalik", vbInformation
DTPicker1.SetFocus
Exit Sub
ElseIf DTPicker2.Value = DTPicker1.Value Then
MsgBox "pilih Tanggal yang berbeda", vbInformation
DTPicker2.SetFocus
Exit Sub
End If
    With CrystalReport1
         .ReportFileName = App.Path & "\Laporan_Harian.rpt" 'assign report file
        .Destination = crptToWindow
        .SelectionFormula = "{ENTRY_NOTA.TANGGAL}>=# " & DTPicker1.Value & "# And {ENTRY_NOTA.TANGGAL}<= #" & DTPicker2.Value & "#"
        .Password = Chr(10) & "rahman" 'membuka password database
        .WindowState = crptMaximized 'maximized - minimized or normal
        .DataFiles(0) = App.Path & "\Database1.mdb" 'get db current path
       .Action = 1 'show report
    End With
End Sub


Private Sub Command_Click()
 Dim strFormula As String
   strFormula = "{TOTAL_NOTA.NO_NOTA}= '" & Combo.Text & "'"
    With CrystalReport1
        .Destination = crptToWindow
        .SelectionFormula = IIf(Combo.Text = "[none]", "", strFormula)
        .ReportFileName = App.Path & "\Laporan_Harian.rpt" 'assign report file
        .Password = Chr(10) & "rahman" 'password
        .WindowState = crptMaximized 'maximized - minimized or normal
        .DataFiles(0) = App.Path & "\Database1.mdb" 'get db current path
        .Action = 1 'show report
    End With
End Sub
Private Sub Command2_Click()
Dim strFormula As String
    strFormula = "{JENIS_PENGELUARAN.KODE}= '" & CboKode.Text & "'"
    With CrystalReport1
        .Destination = crptToWindow
        .SelectionFormula = IIf(CboKode.Text = "[none]", "", strFormula)
        .ReportFileName = App.Path & "\Laporan_Mingguna_Perjenis.rpt" 'assign report file
        .Password = Chr(10) & "rahman" 'password
        .WindowState = crptMaximized 'maximized - minimized or normal
        .DataFiles(0) = App.Path & "\Database1.mdb" 'get db current path
        .Action = 1 'show report
    End With
End Sub


Private Sub Form_Load()
konek
Adodc1.ConnectionString = Database.ConnectionString
Adodc1.RecordSource = "ENTRY_NOTA"
Set DataGrid1.DataSource = Adodc1
Adodc1.Caption = "Count : " & Adodc1.Recordset.RecordCount
Adodc2.ConnectionString = Database.ConnectionString
Adodc2.RecordSource = "TOTAL_NOTA"
Set DataGrid2.DataSource = Adodc2
Adodc2.Caption = "Count : " & Adodc2.Recordset.RecordCount
Adodc3.ConnectionString = Database.ConnectionString
Adodc3.RecordSource = "JENIS_PENGELUARAN"
Set DataGrid3.DataSource = Adodc3
Adodc3.Caption = "Count : " & Adodc3.Recordset.RecordCount
'----------------------------------------------------------------
   Combo.AddItem "[none]"
    Do While Not Adodc2.Recordset.EOF
        Combo.AddItem Adodc2.Recordset!NO_NOTA
       Adodc2.Recordset.MoveNext
    Loop
'--------------------------------------------------------------
    CboKode.AddItem "[none]"
    Do While Not Adodc3.Recordset.EOF
        CboKode.AddItem Adodc3.Recordset!KODE
        Adodc3.Recordset.MoveNext
    Loop
End Sub


Download Surce Code Nya : Coneksi ADo Db password.rar

0 komentar:

Posting Komentar