Private Sub lblFindNow_Click()
Dim itmX As ListItem
Dim CNN As New ADODB.Connection
Dim RST As New ADODB.Recordset
Dim Stpath, strSQL As String
Dim StartDate As String, EndDate As String, Dwmc As String
Stpath = ThisWorkbook.Path & Application.PathSeparator & "採購訂單數據庫.mdb"
CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath
If Sheet1.TXT1.Value = "" Then
MsgBox "沒有搜索的字符串", vbInformation, "信息"
Exit Sub
End If
StartDate = Worksheets(1).TXT3.Value: EndDate = Worksheets(1).TXT4.Value: Dwmc = Worksheets(1).TXT1.Value
strSQL = "Select 貨號,貨名,PO,數量,貨期 from 數據庫1 "
strSQL = strSQL & "Where 貨號 = '" & Dwmc & "'"
strSQL = strSQL & " Order By 貨期 "
On Error Resume Next
RST.Open strSQL, CNN, adOpenDynamic
'Worksheets("sheet3").Range("A5:K10000").ClearContents
'Worksheets("sheet3").Cells(5, 1).CopyFromRecordset RST
后面的代码要怎样写?recordest 中有多条记录,我想直接全部写到listview中去,但下面的代码只能写入一个记录,如果用 do ----loop 则死循环。
我对 DAO和SQL不是很熟,请大家帮帮我
RST.MoveFirst
Set itmX = Worksheets("sheet1").ListView1.ListItems.Add( )
' Do While Not RST.EOF
itmX.SubItems(1) = RST.Fields(1)
itmX.SubItems(2) = RST.Fields(2)
itmX.SubItems(3) = RST.Fields(3)
itmX.SubItems(4) = RST.Fields(4)
'Loop
RST.Close
CNN.Close
End Sub
[此贴子已经被作者于2005-7-15 19:18:17编辑过] |