|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原帖由 store88168 于 2011-3-21 12:43 发表
For i = 1 To 4
t = Me.Controls("TextBox" & i).Text
If Len(t) Then s = s & " and UCase(" & arr(i) & ") like '%" & UCase(t) & "%'"
Next
SQL = "select * from [Sheet1$" & [g1].Cu ...
任何的解释不如你自己看一看:
Public Sub Comm()
Dim i&, j&, arr, s$, t$, SQL$
arr = [g1:j1&""]
For i = 1 To 4
t = Me.Controls("TextBox" & i).Text
If Len(t) Then s = s & " and UCase(" & arr(i) & ") like '%" & UCase(t) & "%'"
Next
MsgBox s
SQL = "select * from [Sheet1$" & [g1].CurrentRegion.Address(0, 0) & "]"
If Len(s) Then SQL = SQL & " where " & Mid(s, 6)
MsgBox SQL
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
With ListView1
.ListItems.Clear
For i = 1 To rs.RecordCount
.ListItems.Add , , rs.Fields(0).Value
For j = 1 To rs.Fields.Count - 1
.ListItems(i).SubItems(j) = rs.Fields(j).Value
Next
rs.MoveNext
Next
End With
rs.MoveFirst
End Sub |
|