Dim adoConn As Object, adoRS As Object
Private Sub CommandButton1_Click()
Set adoRS = CreateObject("ADODB.Recordset")
With adoRS
.ActiveConnection = adoConn
.Open "select * from " & _
"(SELECT 'ThiTruong',f1,f2,f3,f4,f5,round(f6,0),round(f7,0),round(f8,0),f9 FROM [Thitruong$A2:I100] " & _
"Union ALL " & _
"SELECT 'LienSo',f1,f2,f3,f4,f5,round(f6,0),round(f7,0),round(f8,0),f9 FROM [Lienso$A2:I100]) " & _
"WHERE ucase(F2) LIKE '%" & UCase(Me.TextBox1.Text) & "%'"
If Not (.bof And .EOF) Then
ListBox1.ColumnCount = .Fields.Count
ListBox1.Column = .getrows()
End If
.Close
End With
End Sub
Private Sub ListBox1_Click()
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Sheets(ListBox1.List(i, 0)).Select
With Range("a2:a500")
Set c = .Find(ListBox1.List(i, 1), LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then Range(c.Address).EntireRow.Select
End With
End If
Next i
End Sub
Private Sub UserForm_Initialize()
Set adoConn = CreateObject("ADODB.Connection")
With adoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1;"";"
.Open
End With
End Sub
Private Sub UserForm_Terminate()
adoConn.Close
Set adoRS = Nothing: Set adoConn = Nothing
End Sub