Pemfilteran data VB

maSukan kode di bawah ke dalam module
==============
Public koneksi As New ADODB.Connection
Public rsBarang As New ADODB.Recordset

Sub Buka_Koneksi()
koneksi.Open “Provider=Microsoft.Jet.Oledb.4.0;Data Source=” & App.Path & “databasejual.mdb”
koneksi.CursorLocation = adUseClient

rsBarang.Open “barang”, koneksi, adOpenKeyset, adLockOptimistic
End Sub

========================

kode form
====================
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
With rsBarang
Me.Text1(0).Text = rsBarang.Fields(0)
Me.Text1(1).Text = rsBarang.Fields(1)
Me.Text1(2).Text = rsBarang.Fields(2)
End With
Me.Frame1.Visible = True
End If
End Sub

Private Sub Form_Load()
Buka_Koneksi

Set Me.DataGrid1.DataSource = rsBarang
Me.Frame1.Visible = False
End Sub

Private Sub Label4_Click()
Me.Frame1.Visible = False
End Sub

Private Sub txtcari_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
With rsBarang
If Me.txtcari.Text = “” Then
.Filter = adFilterNone
.Requery
Else
.Filter = “jenis =’” & Me.txtcari.Text & “‘”
If Not .EOF Then
Set Me.DataGrid1.DataSource = rsBarang
Else
MsgBox “Data yang anda cari tidak ditemukan..”, vbInformation + vbOKOnly, “Informasi”
End If
End If
End With

End If
End Sub

Private Sub txtfil_Change()
With rsBarang
If Me.txtfil.Text = “” Then
.Filter = adFilterNone
.Requery
Else
.Filter = “jenis like ‘” & Me.txtfil.Text & “*’”
If Not .EOF Then
Set Me.DataGrid1.DataSource = rsBarang
Else
MsgBox “Data yang anda cari tidak ditemukan..”, vbInformation + vbOKOnly, “Informasi”
End If
End If
End With
End Sub

Private Sub txtfil_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Me.DataGrid1.SetFocus
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.