Component : 1. Microsoft ADO Data Control 6.0 (SP4) (OLEDB)
2. Microsoft DataGrid Control 6.0 (OLEDB)
Reference: 1. Microsoft ActiveX Data Objects 2.6 Library
Download Code
Option Explicit Dim Conn As ADODB.Connection Dim rs As ADODB.Recordset Private Sub cmdRefresh_Click() Dim i As Integer Dim strSQL As String Set rs = Nothing Set Conn = Nothing If List2.ListCount >= 1 Then strSQL = "SELECT * FROM Table1 WHERE " For i = 1 To List2.ListCount strSQL = strSQL & "Kode = '" & List2.List(i - 1) & "' OR " Next If Right(strSQL, 3) = "OR " Then strSQL = Left(strSQL, Len(strSQL) - 3) End If Else strSQL = "SELECT * FROM Table1" End If RefreshGrid (strSQL) End Sub Private Sub cmdSelect_Click(Index As Integer) Dim i As Integer Select Case Index Case 0: For i = 0 To List1.ListCount - 1 List1.ListIndex = 0 List2.AddItem List1.Text List1.RemoveItem (0) Next Case 1: If List1.ListIndex >= 0 Then List2.AddItem List1.Text List1.RemoveItem (List1.ListIndex) Else MsgBox "Select Kode Mahasiswa..." End If Case 2: If List2.ListIndex >= 0 Then List1.AddItem List2.Text List2.RemoveItem (List2.ListIndex) Else MsgBox "Select Kode Mahasiswa..." End If Case 3: For i = 0 To List2.ListCount - 1 List2.ListIndex = 0 List1.AddItem List2.Text List2.RemoveItem (0) Next End Select End Sub Private Sub CommandButton1_Click() End End Sub Private Sub Form_Load() RefreshGrid ("SELECT * FROM Table1") rs.MoveFirst While Not rs.EOF List1.AddItem rs.Fields(0) rs.MoveNext Wend End Sub Private Sub List1_DblClick() cmdSelect_Click (1) End Sub Private Sub List1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdSelect_Click (1) End If End Sub Private Sub List2_DblClick() cmdSelect_Click (2) End Sub Private Sub RefreshGrid(strSQL As String) Dim strConn As String Set Conn = New ADODB.Connection Set rs = New ADODB.Recordset strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\db5.mdb;" Conn.CursorLocation = adUseClient Conn.ConnectionString = strConn Conn.Open rs.Open strSQL, _ Conn, adOpenKeyset, adLockOptimistic Set Adodc1.Recordset = rs End Sub Private Sub List2_KeyPress(KeyAscii As Integer) cmdSelect_Click (2) End Sub |
0 komentar:
Komentar Anda
Berikan komentar..