|
本帖最后由 llpsrnfrw 于 2015-4-1 10:57 编辑
代码如下
- Sub search()
- Dim db As New AccessDB
- Dim i As Integer, j As Integer
- Dim strA As String
- Call clear
- db.DBName = ThisWorkBook.path & "\order.mdb"
- strA = ""
- If Not IsEmpty(Range("f1")) Then
- strA = strA & " and ordername like '%" & Trim(Range("f1")) & "%'"
- End If
-
- If Not IsEmpty(Range("f3")) Then
- strA = strA & " and [as] like '%" & Trim(Range("f3")) & "%'"
- End If
-
- If Not IsEmpty(Range("h3")) Then
- strA = strA & " and dv like '%" & Trim(Range("h3")) & "%'"
- End If
- If strA = "" Then
- db.RunSQL "select * from pj"
- Else
- strA = Right(strA, Len(strA) - 4)
- db.RunSQL "select * from pj where " & strA
- End If
-
- With ActiveSheet
- i = 5
- Do Until db.RS.EOF
- For j = 1 To 8
- If j = 4 Then
- .Cells(i, j) = Replace(db.RS.Fields(j - 1), "chr(39)", "'")
- End If
- .Cells(i, j) = db.RS.Fields(j - 1)
- Next
-
- If db.RS.Fields(8) = True Then
- .Cells(i, 9) = Cells(1, 1)
- End If
- i = i + 1
- db.RS.MoveNext 当没有检索条件的时候(即strA为空的时候没有问题),有检索条件的时候这句报错,内存溢出
- Loop
- End With
-
- MsgBox ("Done")
- End Sub
复制代码
求大神指点
|
|