|
请高手指教,下面代码的错误如何解决?
Private Sub 命令0_Click()
Dim row As Integer
Dim col As Integer
Dim conn As Object
Dim rs As Object
Dim sql As String
Dim ExcelApp As Excel.Application
Dim ExcelWst As Worksheet
Set conn = Application.CurrentProject.Connection
m = "电脑报"
sql = "select * from 书本"
'sql = "select * from 书本 where [书名]=" & m
注:在导出表时这段代码没有错误,如果添加了Where条件后,就出现错误。 Set rs = CreateObject("ADODB.Recordset")
rs.Open sql, conn, 1 ' 1 = adOpenKeyset
错误之处在上面这段代码,提示至少有一个参数没有指定。参见附图。
Set ExcelApp = New Excel.Application
Set ExcelWst = ExcelApp.Workbooks.Add.Worksheets(1)
'ExcelWst.Name = "书本"
row = 5
While Not rs.EOF
For col = 0 To rs.Fields.Count - 1
ExcelWst.Cells(row, col + 1) = rs.Fields(col)
Next col
row = row + 1
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Set conn = Nothing
ExcelApp.Visible = True
Dim sname As String
sname = "图书 " + CStr(Date)
ActiveWorkbook.SaveAs sname
End Sub
导出错误.rar
(30.37 KB, 下载次数: 6)
[ 本帖最后由 zhqang 于 2009-8-21 10:17 编辑 ] |
|