Mencari cepat suatu record dengan menampilkan terlebih dahulu pillihan yang mungkin dimaksud kedalam sebuah listBox
Code :
Jika perlu penjelasan,silahkan tinggalkan komentar kalian.
Share
Project : Standard EXE Component Tambahan :
ADODC (Microsoft ADO Data Control 6.0 (OLEDB))
Datagrid (Microsoft Datagrid Control 6.0 (OLEDB))
Controls :
list1 (listBox)
text1 (textbox)
cmdCari (Commandbutton)
lbsuggest (label)
Adodc1, Adodc2 (ADODC)
Datagrid1 (Datagrid)
Code :
- Private Sub cmdcari_Click()
- With Adodc1
- .RecordSource = "SELECT Nama, Alamat FROM TbAlamat WHERE nama like '" + Text1.Text + "%'"
- .Refresh
- End With
- DataGrid1.Refresh
- End Sub
- Private Sub Form_Load()
- Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
- "Data Source=" + App.Path & "\data\db1.mdb;" + _
- "Persist Security Info=False"
- Adodc1.RecordSource = "TbAlamat"
- Adodc1.Refresh
- DataGrid1.Refresh
- Adodc2.ConnectionString = Adodc1.ConnectionString
- Adodc2.RecordSource = "TbAlamat"
- Adodc2.Refresh
- List1.Top = lbsuggest.Top + lbsuggest.Height
- List1.Left = Text1.Left
- List1.Height = 0
- List1.Width = Text1.Width
- List1.Visible = False
- lbsuggest.Visible = False
- End Sub
- Private Sub List1_Click()
- Text1.Text = List1.Text
- List1.Visible = False
- lbsuggest.Visible = False
- End Sub
- Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
- List1.Clear
- List1.Visible = False
- lbsuggest.Visible = False
- n = 0
- If Not Text1.Text = "" Then
- List1.Clear
- With Adodc2
- .RecordSource = "SELECT nama FROM TbAlamat WHERE nama like '" + Text1.Text + "%'"
- .Refresh
- If Not .Recordset.EOF Then
- Do Until .Recordset.EOF
- n = n + 1
- List1.AddItem .Recordset(0)
- .Recordset.MoveNext
- Loop
- List1.Height = n * 225
- If List1.Height > 2250 Then List1.Height = 2250
- List1.Visible = True
- lbsuggest.Visible = True
- End If
- End With
- End If
- End Sub
Jika perlu penjelasan,silahkan tinggalkan komentar kalian.
0 Reply :
Posting Komentar
Jika ada pertanyaan atau request,Komentar pada tab blogger akan lebih memudahkan saya untuk membalasnya karena lebih mudah melakukan pengecekan komentar.