读书人

请教怎样即时弹出Excel形式的查询结果

发布时间: 2012-01-11 22:28:46 作者: rapoo

请问怎样即时弹出Excel形式的查询结果(VBA)?
请问怎样在点击“确定”按钮之后,用Excel弹出查询结果?

我现在程序可以实现把整个Recordset保存为Excel文件,但是不能弹出Excel表格样式的查询结果

谢谢

程序现有代码:

Public rs As ADODB.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
' Open the recordset.
Private Sub Command1_Click()

Set con = New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hotelmag.mdb;Persist Security Info=False "
con.CursorLocation = adUseClient
con.Open
mysql = "select 员工信息.员工号 as 员工号,员工信息.姓名 as 姓名,性别,身份证号,出生日期,政治面貌,科室,职务,家庭住址,电话,考勤编号,考勤日期,考勤时段,出勤情况 from 考勤,员工信息 where 员工信息!科室= ' " & Text1.Text & " ' and 员工信息!员工号=考勤!员工号 "
Set rs = con.Execute(mysql)


'Set rs = Db.OpenRecordset( "SELECT * FROM D:\Program Files\Microsoft Visual Studio\VB98\hotelmag.mdb ") '设置rs
' Open the destination Excel workbook.
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open( "D:\Program Files\Microsoft Visual Studio\VB98\test\Book1.xls ")
' This is all it takes to copy the contents
' of the recordset into the first worksheet
' of Book1.xls.
xlBook.Worksheets(1).Range( "A1 ").CopyFromRecordset rs '*****注意此语句***** execl2000
' Clean up everything.
xlBook.Save
xlBook.Close False
xlApp.Quit
rs.Close
'Db.Close
Set xlBook = Nothing
Set xlApp = Nothing
Set rs = Nothing
End Sub
Private Sub Form_Load()
Text1.Text = " "

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call Command1_Click
End If
End Sub

[解决办法]
xlBook.Save
xlApp .visible=true

这个?

[解决办法]
用Excel弹出查询结果?
是把EXCEL显示出来?哪么你为什么要close它?
你只须xlApp.visible=true不要close就行了,当然set xlApp=nothing之类的语句也不要

读书人网 >VB

热点推荐