|
本帖最后由 sqhsqhli 于 2013-1-22 09:04 编辑
我想把access库中数据导入excel中,如何实现这样的综合查询呢,求大虾指点。
Sub 导入数据()
'代码放在excel模块中
'引用ms activex data object 2.8
Application.ScreenUpdating = False
Dim conn As ADODB.Connection
Dim wn As String
Dim columnname As String
Dim ssql As String
wn = "db1.mdb"
With Sheet1
.Range("a:i").ClearContents
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=microsoft.jet.oledb.4.0;" _
& "Data Source=" & "C:\Documents and Settings\Administrator\桌面\" & wn'数据库放在桌面
conn.Open
If conn.State = adStateOpen Then
ssql = "select name from " & "表1"
.Range("a1").CopyFromRecordset conn.Execute(ssql)
'??????????????????????????????????????????????????????????????????
'请问如何修改这两句,使之直接输出相对应的科室名称,求指点
ssql = "select id from " & "表2"
.Range("b1").CopyFromRecordset conn.Execute(ssql)
'??????????????????????????????????????????????????????????????????
End If
conn.Close
Set conn = Nothing
End With
End Sub
db1.rar
(8.12 KB, 下载次数: 11)
|
|