Got this Code here:
My data is inside table called table3. Data in table go in through another userform for entry.
I got 7 columns ,but want to search in just two of them . Sheet is called CaFR
Private Sub CommandButton1_Click()
Dim cn As Object, rs As Object, temp
Me.ListBox1.Clear
temp = Me.TextBox1.Value
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Properties("Extended Properties") = "Excel 12.0;HDR=Yes;"
.Open ThisWorkbook.FullName
End With
rs.Open "SELECT * FROM `CaFR$` WHERE CStr( cathegory) = '" & temp & "'", cn, 3
If rs.RecordCount Then Me.ListBox1.Column = rs.GetRows
Set cn = Nothing: Set rs = Nothing
End Sub
Bookmarks