Option Explicit
Dim mykoneksi As Connection
Dim WithEvents tb_1 As Recordset
Dim WithEvents tb_2 As Recordset
Dim record As Integer
Dim field As Integer
Dim page As Integer
Dim jumlah_per_halaman As Integer
Dim eop As Integer
Dim j As Integer
Private Sub cbopage_Click()
Dim i As Integer
Dim tempBottom As Integer
Dim tempTop As Integer
If cbopage.Text > 1 And _
cbopage.Text < tb_1.PageCount Then cmdprev.Enabled = True: cmdnext.Enabled = True
If cbopage.Text = tb_1.PageCount Then cmdprev.Enabled = True: cmdnext.Enabled = False
If cbopage.Text <= 1 Then cmdprev.Enabled = False: cmdnext.Enabled = True
If cbopage.ListCount = 1 Then cmdprev.Enabled = False: cmdnext.Enabled = False
If cbopage.Text = "1" Then
j = 0
tb_1.MoveFirst
For i = 1 To jumlah_per_halaman
j = j + 1
tb_1.MoveNext
If tb_1.EOF Then Exit For
Next i
Else
j = 0
tb_1.MoveFirst
eop = cbopage.Text * jumlah_per_halaman
tb_1.Move eop - jumlah_per_halaman
For i = 1 To jumlah_per_halaman
j = j + 1
tb_1.MoveNext
If tb_1.EOF Then Exit For
Next i
End If
tempBottom = (cbopage * jumlah_per_halaman) - (jumlah_per_halaman - 1)
tempTop = ((cbopage * jumlah_per_halaman) - (jumlah_per_halaman - 1)) + (j - 1)
Set tb_2 = New Recordset
tb_2.Open "SELECT * FROM table1 WHERE no_urut>=" _
& tempBottom & " AND no_urut<=" & tempTop & "", _
mykoneksi, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = tb_2.DataSource
record = tb_2.RecordCount
field = tb_2.Fields.Count
DoEvents
End Sub
Private Sub cbo_perpage_Click()
Dim i As Integer
jumlah_per_halaman = cbo_perpage.Text
tb_1.PageSize = jumlah_per_halaman
page = tb_1.PageCount
cbopage.Clear
For i = 1 To page
cbopage.AddItem i
Next i
cbopage.Text = cbopage.List(0)
End Sub
Private Sub cmdCLOSE_Click()
Unload Me
End Sub
Private Sub cmdnext_Click()
cbopage.Text = cbopage.Text + 1
If cbopage.Text > 1 Then cmdprev.Enabled = True
If cbopage.Text >= tb_1.PageCount Then cmdnext.Enabled = False: cmdprev.SetFocus
End Sub
Private Sub cmdprev_Click()
cbopage.Text = cbopage.Text - 1
If cbopage.Text > 1 Then cmdprev.Enabled = True: cmdprev.SetFocus
If cbopage.Text <= 1 Then cmdprev.Enabled = False: cmdnext.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
Set mykoneksi = New Connection
mykoneksi.CursorLocation = adUseClient
mykoneksi.Open "PROVIDER=MSDataShape;Data PROVIDER=" & _
"Microsoft.Jet.OLEDB.4.0;Data Source=" _
& App.Path & "\db1.mdb;"
Set tb_1 = New Recordset
tb_1.Open "SELECT * FROM table1", mykoneksi
For i = 10 To 35 Step 10
cbo_perpage.AddItem i
Next i
cbo_perpage.Text = cbo_perpage.List(0)
jumlah_per_halaman = cbo_perpage.List(0)
tb_1.PageSize = jumlah_per_halaman
page = tb_1.PageCount
cmdprev.Enabled = False
cmdnext.Enabled = True
Exit Sub
Pesan:
MsgBox Err.Number & " - " & Err.Description
End
End Sub
Contoh Kode membuat halaman vb 6 diatas masih sederhana dan bisa dikembangkan sesuai kebutuhan kita. NB : "mungkin ada rekan-rekan yang ahli mohon di share... terima kasih".
Download Source disini.
0 komentar:
Komentar Anda
Berikan komentar..